<?php
    /**
     * Sticky Site Logo Section
     * 
     * @package Blog Bee
     * @since 1.0.0
     */
    namespace BBE\Customizer\Section;

    use BBE\Customizer\Section\Section as Section;
    use BBE\Customizer\Section\Sticky_Header_Trait as Sticky_Header_Trait;
    use BBE\Customizer\Section\Search_Icon as Search_Icon;
    use BBE\Customizer\Theme_Defaults as Theme_Defaults;
    use BBE\Helpers as Helpers;

    if( ! class_exists( __NAMESPACE__ . '\\Sticky_Search_Icon' ) ) {
        /**
         * Site Logo class
         */
        class Sticky_Search_Icon extends Section {

            use Sticky_Header_Trait;

            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-sticky-search-icon';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'sticky_search_icon_section' );
                $this->add_control( 'sticky_search_icon_redirect' );
                $this->add_control( 'sticky_search_icon_icon_color' );
                $this->add_control( 'sticky_search_icon_background' );
                $this->add_control( 'sticky_search_icon_border_color' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'sticky_search_icon_redirect' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_search_icon_icon_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_search_icon_background' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_search_icon_border_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'sticky_search_icon_section' =>  [
                        'title' =>  esc_html__( 'Search Icon', 'blog-bee' ),
                        'section_to_open' =>  'sticky_header_section',
                        'active_callback'   =>  function(){
                            return $this->is_active( 'search-icon' );
                        }
                    ],
                    'sticky_search_icon_redirect' =>  [
                        'label' =>  esc_html__( 'Edit Search Icon', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'search_icon_section',
                    ],
                    'sticky_search_icon_icon_color' =>  [
                        'label' =>  esc_html__( 'Icon Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                    ],
                    'sticky_search_icon_background' =>  [
                        'label' =>  esc_html__( 'Background', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                        'color_types'   =>  [ 'solid', 'gradient' ]
                    ],
                    'sticky_search_icon_border_color' =>  [
                        'label' =>  esc_html__( 'Border Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'sticky_search_icon_redirect' =>  '',
                    'sticky_search_icon_icon_color' =>  [
                        'initial'   =>  $this->get_color( [ 'value' => '#000' ] ),
                        'hover'   =>  $this->get_color(),
                    ],
                    'sticky_search_icon_background' =>  [
                        'initial'   =>  $this->get_color( [ 'value' => '' ] ),
                        'hover'   =>  $this->get_color( [ 'value' => '' ] ),
                    ],
                    'sticky_search_icon_border_color' =>  [
                        'initial'   =>  $this->get_color( [ 'value' => '#efefef' ] ),
                        'hover'   =>  $this->get_color(),
                    ],
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                if( ! $this->is_active( 'search-icon' ) ) return [];
                $dynamic_args = [
                    'sticky_search_icon_icon_color'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_search_icon_icon_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_search_icon_icon_color' ),
                        'selector'  =>  '.bbe-light .bbe-header .bbe-sticky-header .bbe-search-icon i, .bbe-light .bbe-header .bbe-sticky-header .bbe-search-icon .icon svg',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'sticky_search_icon_background' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_search_icon_background' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_search_icon_background' ),
                        'selector'  =>  '.bbe-light .bbe-sticky-header .bbe-search-icon.filled i',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                    'sticky_search_icon_border_color'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_search_icon_border_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'sticky_search_icon_border_color' ),
                        'selector'  =>  '.bbe-light .bbe-sticky-header .bbe-search-icon.outline i',
                        'property'  =>  '--bbe-site-border-color'
                    ],
                ];
                return $dynamic_args;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                Search_Icon::get_instance()->render_html();
            }
        }
        Sticky_Search_Icon::get_instance();
    }