<?php
/**
 * Tabs class.
 *
 * @package SaveToWishlist\Classes\Admin\Settings
 * @since 1.0.0
 */
namespace SaveToWishlist\Classes\Admin\Settings;

use SaveToWishlist\Abstracts\Singleton;
use SaveToWishlist\Classes\Importers\Importer_Factory;

/**
 * Class Tabs
 *
 * This class serves as the tabs class.
 */
class Tabs extends Singleton {

    /**
     * Parent tabs.
     *
     * @since 1.0.0
     * @access public
     * @return array
     */
    public function tabs() {
        $tabs                    = array();
        $tabs['saveto_wishlist'] = array(
            'label' => __( 'SaveTo Wishlist', 'saveto-wishlist-lite-for-woocommerce' ),
            'child' => array(),
        );

        // Filter to modify parent tabs.
        $tabs = apply_filters( 'stwlite_admin_setting_default_parent_tabs', $tabs );

        // Child tabs.
        $tabs = $this->_child_tabs( $tabs );

        return $tabs;
    }

    /**
     * Child tabs.
     *
     * @param array $tabs Tabs.
     *
     * @since 1.0.0
     * @access private
     * @return array
     */
    private function _child_tabs( $tabs ) {
        $child_tabs = array();

        // General tab.
        $child_tabs = $this->_default_general_tab_sections( $child_tabs );

        // Wishlist page tab.
        $child_tabs = $this->_default_wishlist_page_tab_sections( $child_tabs );

        // Wishlist Guest tab.
        $child_tabs = $this->_default_wishlist_guest_tab_sections( $child_tabs );

        // Button tab.
        $child_tabs = $this->_default_button_tab_sections( $child_tabs );

        // Importer tab.
        $child_tabs = $this->_default_importer_tab_sections( $child_tabs );

        // Filter to modify child tabs.
        $child_tabs = apply_filters( 'stwlite_admin_setting_default_child_tabs', $child_tabs );

        $tabs['saveto_wishlist']['child'] = $child_tabs;

        return $tabs;
    }

    /**
     * Get default general tab sections.
     *
     * @param array $child_tabs Child tabs.
     *
     * @since 1.0.0
     * @access private
     * @return array
     */
    private function _default_general_tab_sections( $child_tabs ) {
        $general_tab_sections = array();

        $general_tab_sections['save_to_wishlist_settings'] = array(
            'label' => '',
            'desc'  => '',
        );
        $general_tab_sections['wishlist_action_settings']  = array(
            'label' => __( 'Wishlist Action', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => '',
        );

        // Filter to modify default general tab sections.
        $general_tab_sections = apply_filters( 'stwlite_admin_setting_default_general_tab_sections', $general_tab_sections );

        $general_tab = array(
            'sort'     => 1,
            'key'      => 'general',
            'label'    => __( 'General', 'saveto-wishlist-lite-for-woocommerce' ),
            'icon'     => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-settings-icon lucide-settings w-4 h-4 mr-3"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></svg>',
            'sections' => $general_tab_sections,
        );

        // Add general tab to child tabs.
        $general_tab = apply_filters( 'stwlite_admin_setting_default_general_tab', $general_tab );

        $child_tabs['general'] = $general_tab;

        return $child_tabs;
    }

    /**
     * Get default wishlist page tab sections.
     *
     * @param array $child_tabs Child tabs.
     *
     * @since 1.0.0
     * @access private
     * @return array
     */
    private function _default_wishlist_page_tab_sections( $child_tabs ) {
        $wishlist_page_tab_sections = array();

        $wishlist_page_tab_sections['wishlist_page_text_settings']   = array(
            'label' => '',
            'desc'  => '',
        );
        $wishlist_page_tab_sections['wishlist_page_switch_settings'] = array(
            'label' => '',
            'desc'  => '',
        );
        $wishlist_page_tab_sections['wishlist_page_styles_settings'] = array(
            'label' => __( 'Styles', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => '',
        );

        // Filter to modify default wishlist page tab sections.
        $wishlist_page_tab_sections = apply_filters( 'stwlite_admin_setting_default_wishlist_page_tab_sections', $wishlist_page_tab_sections );

        $wishlist_page_tab = array(
            'sort'     => 2,
            'key'      => 'wishlist_page',
            'label'    => __( 'Wishlist Page', 'saveto-wishlist-lite-for-woocommerce' ),
            'icon'     => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-panels-top-left-icon lucide-panels-top-left w-4 h-4 mr-3"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/><path d="M9 21V9"/></svg>',
            'sections' => $wishlist_page_tab_sections,
        );

        // Filter to modify default wishlist page tab.
        $wishlist_page_tab = apply_filters( 'stwlite_admin_setting_default_wishlist_page_tab', $wishlist_page_tab );

        $child_tabs['wishlist_page'] = $wishlist_page_tab;

        return $child_tabs;
    }

    /**
     * Get default wishlist guest tab sections.
     *
     * @param array $child_tabs Child tabs.
     *
     * @since 1.0.0
     * @access private
     * @return array
     */
    private function _default_wishlist_guest_tab_sections( $child_tabs ) {
        $wishlist_guest_tab_sections = array();

        $wishlist_guest_tab_sections['wishlist_guest_settings'] = array(
            'label' => '',
            'desc'  => '',
        );

        // Filter to modify default wishlist guest tab sections.
        $wishlist_guest_tab_sections = apply_filters( 'stwlite_admin_setting_default_wishlist_guest_tab_sections', $wishlist_guest_tab_sections );

        $wishlist_guest_tab = array(
            'sort'     => 3,
            'key'      => 'wishlist_guest',
            'label'    => __( 'Guest Options', 'saveto-wishlist-lite-for-woocommerce' ),
            'icon'     => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-users-icon lucide-users w-4 h-4 mr-3"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><path d="M16 3.128a4 4 0 0 1 0 7.744"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><circle cx="9" cy="7" r="4"/></svg>',
            'sections' => $wishlist_guest_tab_sections,
        );

        // Filter to modify default wishlist guest tab.
        $wishlist_guest_tab = apply_filters( 'stwlite_admin_setting_default_wishlist_guest_tab', $wishlist_guest_tab );

        $child_tabs['wishlist_guest'] = $wishlist_guest_tab;

        return $child_tabs;
    }

    /**
     * Get default button tab sections.
     *
     * @param array $child_tabs Child tabs.
     *
     * @since 1.0.0
     * @access private
     * @return array
     */
    private function _default_button_tab_sections( $child_tabs ) {
        $button_tab_sections = array();

        $button_tab_sections['wishlist_button_settings']           = array(
            'label' => __( 'Button Settings', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => '',
        );
        $button_tab_sections['wishlist_frontend_styling_settings'] = array(
            'label' => __( 'Frontend Styling', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => __( 'Control how the plugin\'s frontend stylesheet is loaded so it can coexist with your theme\'s CSS.', 'saveto-wishlist-lite-for-woocommerce' ),
        );
        $button_tab_sections['wishlist_product_page_settings']     = array(
            'label' => __( 'Product Page', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => __( 'Wishlist button placement and style on product page.', 'saveto-wishlist-lite-for-woocommerce' ),
        );
        $button_tab_sections['wishlist_shop_page_settings']        = array(
            'label' => __( 'Shop Page', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => __( 'Wishlist button placement and style on shop page.', 'saveto-wishlist-lite-for-woocommerce' ),
        );
        $button_tab_sections['wishlist_cart_page_settings']        = array(
            'label' => __( 'Cart Page', 'saveto-wishlist-lite-for-woocommerce' ),
            'desc'  => __( 'Wishlist button label and style on cart page.', 'saveto-wishlist-lite-for-woocommerce' ),
        );

        // Filter to modify default button tab sections.
        $button_tab_sections = apply_filters( 'stwlite_admin_setting_default_button_tab_sections', $button_tab_sections );

        $button_tab = array(
            'sort'     => 4,
            'key'      => 'wishlist_button',
            'label'    => __( 'Button Placement & Styles', 'saveto-wishlist-lite-for-woocommerce' ),
            'icon'     => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mouse-pointer-icon lucide-mouse-pointer w-4 h-4 mr-3"><path d="M12.586 12.586 19 19"/><path d="M3.688 3.037a.497.497 0 0 0-.651.651l6.5 15.999a.501.501 0 0 0 .947-.062l1.569-6.083a2 2 0 0 1 1.448-1.479l6.124-1.579a.5.5 0 0 0 .063-.947z"/></svg>',
            'sections' => $button_tab_sections,
        );

        // Filter to modify default button tab.
        $button_tab = apply_filters( 'stwlite_admin_setting_default_wishlist_button_tab', $button_tab );

        $child_tabs['wishlist_button'] = $button_tab;

        return $child_tabs;
    }

    /**
     * Get default importer tab sections.
     *
     * @param array $child_tabs Child tabs.
     *
     * @since 1.0.0
     * @access private
     * @return array
     */
    private function _default_importer_tab_sections( $child_tabs ) {
        // Hide the Imports tab entirely when no source wishlist plugin is active.
        if ( empty( Importer_Factory::get_detected_importers() ) ) {
            return $child_tabs;
        }

        $importer_tab_sections = array();

        $importer_tab_sections['importer_settings'] = array(
            'label' => '',
            'desc'  => '',
        );

        // Filter to modify default importer tab sections.
        $importer_tab_sections = apply_filters( 'stwlite_admin_setting_default_importer_tab_sections', $importer_tab_sections );

        $importer_tab = array(
            'sort'     => 5,
            'key'      => 'importer',
            'no_save'  => true,
            'label'    => __( 'Imports', 'saveto-wishlist-lite-for-woocommerce' ),
            'icon'     => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-download-icon lucide-download w-4 h-4 mr-3"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/></svg>',
            'sections' => $importer_tab_sections,
        );

        // Filter to modify default importer tab.
        $importer_tab = apply_filters( 'stwlite_admin_setting_default_importer_tab', $importer_tab );

        $child_tabs['importer'] = $importer_tab;

        return $child_tabs;
    }
}
