<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Default theme builder tab definitions (unfiltered).
 *
 * Third-party plugins should not edit this file. Use:
 * - sifency_addons_exclude_themebuilder_tabs()
 * - sifency_addons_register_themebuilder_tabs()
 * - Filters: sifency_addons_themebuilder_tabs, sifency_addons_excluded_themebuilder_tabs
 *
 * @see theme-builder/includes/admin/class-themebuilder-navigation-registry.php
 * @see DEVELOPER.md
 *
 * @return array<string, array>
 */
function sifency_addons_themebuilder_get_default_tabs() {
	return array(
		'all'               => array(
			'label'      => __( 'All Templates', 'sifency-addons' ),
			'icon'       => 'dashicons-screenoptions',
			'sync_state' => false,
		),
		'header'            => array(
			'label'      => __( 'Main Header', 'sifency-addons' ),
			'icon'       => 'dashicons-editor-insertmore',
			'sync_state' => false,
		),
		'topbar'            => array(
			'label'      => __( 'Top Header', 'sifency-addons' ),
			'icon'       => 'dashicons-editor-insertmore',
			'sync_state' => true,
		),
		'subheader'         => array(
			'label'      => __( 'Subheader', 'sifency-addons' ),
			'icon'       => 'dashicons-align-wide',
			'sync_state' => false,
		),
		'after-subheader'   => array(
			'label'      => __( 'After Subheader', 'sifency-addons' ),
			'icon'       => 'dashicons-align-wide',
			'sync_state' => false,
		),
		'footer'            => array(
			'label'      => __( 'Main Footer', 'sifency-addons' ),
			'icon'       => 'dashicons-align-full-width',
			'sync_state' => false,
		),
		'pre-before-footer' => array(
			'label'      => __( 'Pre Before Footer', 'sifency-addons' ),
			'icon'       => 'dashicons-align-full-width',
			'sync_state' => false,
		),
		'before-footer'     => array(
			'label'      => __( 'Before Footer', 'sifency-addons' ),
			'icon'       => 'dashicons-align-full-width',
			'sync_state' => false,
		),
		'offcanvas'         => array(
			'label'      => __( 'Offcanvas', 'sifency-addons' ),
			'icon'       => 'dashicons-menu',
			'sync_state' => false,
		),
		'popup'             => array(
			'label'      => __( 'Popup', 'sifency-addons' ),
			'icon'       => 'dashicons-feedback',
			'sync_state' => true,
		),
		'scrollup'          => array(
			'label'      => __( 'Scroll to Up', 'sifency-addons' ),
			'icon'       => 'dashicons-arrow-up-alt2',
			'sync_state' => false,
		),
		'error_404'         => array(
			'label'      => __( '404 Page', 'sifency-addons' ),
			'icon'       => 'dashicons-warning',
			'sync_state' => true,
		),
		'post-archive'      => array(
			'label'      => __( 'Post Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-admin-post',
			'sync_state' => true,
			'tooltip'    => __( 'Exclude other post types to avoid conflicts', 'sifency-addons' ),
		),
		'post'              => array(
			'label'      => __( 'Single Post', 'sifency-addons' ),
			'icon'       => 'dashicons-welcome-write-blog',
			'sync_state' => false,
		),
		'shop'              => array(
			'label'      => __( 'Shop Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-cart',
			'sync_state' => true,
		),
		'product'           => array(
			'label'      => __( 'Single Product', 'sifency-addons' ),
			'icon'       => 'dashicons-products',
			'sync_state' => true,
		),
		'service-archive'   => array(
			'label'      => __( 'Service Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-hammer',
			'sync_state' => true,
		),
		'service'           => array(
			'label'      => __( 'Single Service', 'sifency-addons' ),
			'icon'       => 'dashicons-admin-tools',
			'sync_state' => true,
		),
		'team-archive'      => array(
			'label'      => __( 'Team Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-groups',
			'sync_state' => true,
		),
		'team'              => array(
			'label'      => __( 'Single Member', 'sifency-addons' ),
			'icon'       => 'dashicons-businessman',
			'sync_state' => true,
		),
		'portfolio-archive' => array(
			'label'      => __( 'Portfolio Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-portfolio',
			'sync_state' => true,
		),
		'portfolio'         => array(
			'label'      => __( 'Single Portfolio', 'sifency-addons' ),
			'icon'       => 'dashicons-format-gallery',
			'sync_state' => true,
		),
		'event-archive'     => array(
			'label'      => __( 'Event Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-calendar-alt',
			'sync_state' => true,
		),
		'event'             => array(
			'label'      => __( 'Single Event', 'sifency-addons' ),
			'icon'       => 'dashicons-megaphone',
			'sync_state' => true,
		),
		'career-archive'    => array(
			'label'      => __( 'Career Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-clipboard',
			'sync_state' => true,
		),
		'career'            => array(
			'label'      => __( 'Single Job', 'sifency-addons' ),
			'icon'       => 'dashicons-id-alt',
			'sync_state' => true,
		),
		'doc-archive'       => array(
			'label'      => __( 'Doc Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-media-document',
			'sync_state' => true,
		),
		'documentation'     => array(
			'label'      => __( 'Single Doc', 'sifency-addons' ),
			'icon'       => 'dashicons-book-alt',
			'sync_state' => true,
		),
		'digital-archive'   => array(
			'label'      => __( 'Digital Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-media-archive',
			'sync_state' => true,
		),
		'digital'           => array(
			'label'      => __( 'Single Digital', 'sifency-addons' ),
			'icon'       => 'dashicons-media-archive',
			'sync_state' => true,
		),
		'edd-archive'       => array(
			'label'      => __( 'EDD Archive', 'sifency-addons' ),
			'icon'       => 'dashicons-download',
			'sync_state' => true,
			'beta'       => true,
		),
		'edd'               => array(
			'label'      => __( 'Single EDD', 'sifency-addons' ),
			'icon'       => 'dashicons-media-archive',
			'sync_state' => true,
			'beta'       => true,
		),
		'trash'             => array(
			'label'      => __( 'Restore', 'sifency-addons' ),
			'icon'       => 'dashicons-trash',
			'sync_state' => false,
		),
	);
}

/**
 * Filtered theme builder tabs (use everywhere instead of get_default_tabs).
 *
 * @return array<string, array>
 */
function sifency_addons_themebuilder_get_tabs() {
	if ( class_exists( 'Sifency_Addons_Themebuilder_Navigation_Registry' ) ) {
		return Sifency_Addons_Themebuilder_Navigation_Registry::get_tabs();
	}

	$tabs = sifency_addons_themebuilder_get_default_tabs();

	/**
	 * @param array<string, array> $tabs Tab slug => config.
	 */
	$tabs = apply_filters( 'sifency_addons_themebuilder_tabs', $tabs );

	$excluded = apply_filters( 'sifency_addons_excluded_themebuilder_tabs', array() );
	if ( is_array( $excluded ) ) {
		foreach ( $excluded as $tab_slug ) {
			unset( $tabs[ (string) $tab_slug ] );
		}
	}

	return $tabs;
}

/**
 * Default sidebar navigation groups for the theme builder admin page.
 *
 * @return array<string, array>
 */
function sifency_addons_themebuilder_get_default_nav_structure() {
	return array(
		'overview'      => array(
			'type' => 'single',
			'slug' => 'all',
		),
		'header'        => array(
			'type'  => 'group',
			'label' => __( 'Header', 'sifency-addons' ),
			'icon'  => 'dashicons-editor-kitchensink',
			'items' => array( 'header', 'subheader', 'after-subheader', 'topbar' ),
		),
		'footer'        => array(
			'type'  => 'group',
			'label' => __( 'Footer', 'sifency-addons' ),
			'icon'  => 'dashicons-editor-insertmore',
			'items' => array( 'footer', 'pre-before-footer', 'before-footer' ),
		),
		'general'       => array(
			'type'  => 'group',
			'label' => __( 'General', 'sifency-addons' ),
			'icon'  => 'dashicons-editor-insertmore',
			'items' => array( 'offcanvas', 'popup', 'scrollup', 'error_404' ),
		),
		'blog'          => array(
			'type'  => 'group',
			'label' => __( 'Blog', 'sifency-addons' ),
			'icon'  => 'dashicons-admin-post',
			'items' => array( 'post-archive', 'post' ),
		),
		'woocommerce'   => array(
			'type'  => 'group',
			'label' => __( 'WooCommerce', 'sifency-addons' ),
			'icon'  => 'dashicons-cart',
			'items' => array( 'shop', 'product' ),
		),
		'services'      => array(
			'type'  => 'group',
			'icon'  => 'dashicons-hammer',
			'label' => __( 'Services', 'sifency-addons' ),
			'items' => array( 'service-archive', 'service' ),
		),
		'team'          => array(
			'type'  => 'group',
			'label' => __( 'Team', 'sifency-addons' ),
			'icon'  => 'dashicons-groups',
			'items' => array( 'team-archive', 'team' ),
		),
		'portfolio'     => array(
			'type'  => 'group',
			'label' => __( 'Portfolio', 'sifency-addons' ),
			'icon'  => 'dashicons-portfolio',
			'items' => array( 'portfolio-archive', 'portfolio' ),
		),
		'events'        => array(
			'type'  => 'group',
			'label' => __( 'Events', 'sifency-addons' ),
			'icon'  => 'dashicons-calendar-alt',
			'items' => array( 'event-archive', 'event' ),
		),
		'career'        => array(
			'type'  => 'group',
			'icon'  => 'dashicons-clipboard',
			'label' => __( 'Careers', 'sifency-addons' ),
			'items' => array( 'career-archive', 'career' ),
		),
		'documentation' => array(
			'type'  => 'group',
			'label' => __( 'Documentation', 'sifency-addons' ),
			'icon'  => 'dashicons-media-document',
			'items' => array( 'doc-archive', 'documentation' ),
		),
		'digital'       => array(
			'type'  => 'group',
			'label' => __( 'Digital Goods', 'sifency-addons' ),
			'items' => array( 'digital-archive', 'digital' ),
			'icon'  => 'dashicons-media-archive',
		),
		'edd'           => array(
			'type'  => 'group',
			'label' => __( 'EDD', 'sifency-addons' ),
			'icon'  => 'dashicons-download',
			'items' => array( 'edd-archive', 'edd' ),
		),
		'system'        => array(
			'type' => 'single',
			'slug' => 'trash',
		),
	);
}

/**
 * Filtered sidebar navigation for the theme builder admin page.
 *
 * @return array<string, array>
 */
function sifency_addons_themebuilder_get_nav_structure() {
	if ( class_exists( 'Sifency_Addons_Themebuilder_Navigation_Registry' ) ) {
		return Sifency_Addons_Themebuilder_Navigation_Registry::get_nav_structure();
	}

	return sifency_addons_themebuilder_get_default_nav_structure();
}
