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

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

            use Sticky_Header_Trait;

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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'sticky_time_section' );
                $this->add_control( 'sticky_time_redirect' );
                $this->add_control( 'sticky_time_color' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'sticky_time_redirect' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_time_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_time_section' =>  [
                        'title' =>  esc_html__( 'Time', 'blog-bee' ),
                        'section_to_open' =>  'sticky_header_section',
                        'active_callback'   =>  function(){
                            return $this->is_active( 'time' );
                        }
                    ],
                    'sticky_time_redirect' =>  [
                        'label' =>  esc_html__( 'Edit Time', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'time_section',
                    ],
                    'sticky_time_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_time_redirect' =>  '',
                    'sticky_time_color' =>   $this->get_color( [ 'value' => '#000' ] ),
                    'sticky_time_background' => $this->get_color( [ 'value' => '' ] ),
                ] );
            }

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

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