<?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\Custom_Button as Custom_Button;
    use BBE\Customizer\Theme_Defaults as Theme_Defaults;
    use BBE\Helpers as Helpers;

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

            use Sticky_Header_Trait;

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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'sticky_custom_button_section' );
                $this->add_control( 'sticky_custom_button_redirect' );
                $this->add_control( 'sticky_custom_button_text_color' );
                $this->add_control( 'sticky_custom_button_background' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'sticky_custom_button_redirect' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_custom_button_text_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_custom_button_background' =>  [
                        '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_custom_button_section' =>  [
                        'title' =>  esc_html__( 'Custom Button', 'blog-bee' ),
                        'section_to_open' =>  'sticky_header_section',
                        'active_callback'   =>  function(){
                            return $this->is_active( 'custom-button' );
                        }
                    ],
                    'sticky_custom_button_redirect' =>  [
                        'label' =>  esc_html__( 'Edit Custom Button', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'custom_button_section',
                    ],
                    'sticky_custom_button_text_color' =>  [
                        'label' =>  esc_html__( 'Text / Icon Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                    ],
                    'sticky_custom_button_background' =>  [
                        'label' =>  esc_html__( 'Background Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                        'color_types'   =>  [ 'solid', 'gradient' ]
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'sticky_custom_button_redirect' =>  '',
                    'sticky_custom_button_text_color' =>  [
                        'initial'   =>  $this->get_color( [ 'value' =>  '#fff' ] ),
                        'hover'   =>  $this->get_color( [ 'value' =>  '#fff' ] ),
                    ],
                    'sticky_custom_button_background' =>  [
                        'initial'   =>  $this->get_color( [ 'value' =>  '#3B5CFF' ] ),
                        'hover'   =>  $this->get_color( [ 'value' =>  '#5d76f1' ] ),
                    ],
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                if( ! $this->is_active( 'custom-button' ) ) return [];
                $dynamic_args = [
                    'sticky_custom_button_text_color' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_custom_button_text_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_custom_button_text_color' ),
                        'selector'  =>  '.bbe-header .bbe-sticky-header .custom-button-link',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'sticky_custom_button_background' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_custom_button_background' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_custom_button_background' ),
                        'selector'  =>  '.bbe-header .bbe-sticky-header .custom-button-link',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                ];
                return $dynamic_args;
            }

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