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

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

    use function esc_html__;
    use function esc_attr;

    if( ! class_exists( __NAMESPACE__ . '\\Sticky_Divider_One' ) ) {
        /**
         * Sticky_Divider_One class
         */
        class Sticky_Divider_One extends Section {

            use Sticky_Header_Trait;

            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-sticky-header-divider-1';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'sticky_divider_one_section' );
                $this->add_control( 'sticky_divider_one_redirect' );
                $this->add_control( 'sticky_divider_one_color' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'sticky_divider_one_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_divider_one_redirect' =>  [
                        '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_divider_one_section' =>  [
                        'title' =>  esc_html__( 'Sticky Divider 1', 'blog-bee' ),
                        'active_callback'   =>  function(){
                            return $this->is_active( 'header-divider-1' );
                        },
                        'section_to_open' =>  'sticky_header_section'
                    ],
                    'sticky_divider_one_redirect' =>  [
                        'label' =>  esc_html__( 'Edit Divider 1', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'header_divider_one_section'
                    ],
                    'sticky_divider_one_color' =>  [
                        'label' =>  esc_html__( 'Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'sticky_divider_one_redirect' =>  '',
                    'sticky_divider_one_color' =>  $this->get_color( [ 'value' => '#30344b' ] ),
                ] );
            }

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

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