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

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

            use Sticky_Header_Trait;

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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'sticky_dark_mode_section' );
                $this->add_control( 'sticky_dark_mode_redirect' );
                $this->add_control( 'sticky_dark_mode_light_color' );
                $this->add_control( 'sticky_dark_mode_dark_color' );
                $this->add_control( 'sticky_dark_mode_light_background' );
                $this->add_control( 'sticky_dark_mode_dark_background' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'sticky_dark_mode_light_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_dark_mode_redirect' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_dark_mode_dark_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_dark_mode_light_background' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'sticky_dark_mode_dark_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_dark_mode_section' =>  [
                        'title' =>  esc_html__( 'Dark Mode', 'blog-bee' ),
                        'section_to_open' =>  'sticky_header_section',
                        'active_callback'   =>  function(){
                            return $this->is_active( 'dark-mode' );
                        }
                    ],
                    'sticky_dark_mode_redirect' =>  [
                        'label' =>  esc_html__( 'Edit Dark Mode', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'dark_mode_section',
                    ],
                    'sticky_dark_mode_light_color' =>  [
                        'label' =>  esc_html__( 'Light Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                    ],
                    'sticky_dark_mode_dark_color' =>  [
                        'label' =>  esc_html__( 'Dark Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                    ],
                    'sticky_dark_mode_light_background' =>  [
                        'label' =>  esc_html__( 'Light Background', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                        'color_types'   =>  [ 'solid', 'gradient' ]
                    ],
                    'sticky_dark_mode_dark_background' =>  [
                        'label' =>  esc_html__( 'Dark Background', '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_dark_mode_redirect' =>  '',
                    'sticky_dark_mode_light_color' =>  [
                        'initial'   =>  $this->get_color( [ 'value' =>  '#30344b' ] ),
                        'hover' =>  $this->get_color()
                    ],
                    'sticky_dark_mode_dark_color' =>  [
                        'initial'   =>  $this->get_color( [ 'value' =>  '#fff' ] ),
                        'hover' =>  $this->get_color()
                    ],
                    'sticky_dark_mode_light_background' =>  [
                        'initial'   =>  $this->get_color( [ 'value' => '' ] ),
                        'hover' =>  $this->get_color( [ 'value' => '' ] )
                    ],
                    'sticky_dark_mode_dark_background' =>  [
                        'initial'   =>  $this->get_color( [ 'value' => '' ] ),
                        'hover' =>  $this->get_color( [ 'value' => '' ] )
                    ],
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                if( ! $this->is_active( 'dark-mode' ) ) return [];
                $dynamic_args = [
                    'sticky_dark_mode_light_color' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_dark_mode_light_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_dark_mode_light_color' ),
                        'selector'  =>  '.bbe-sticky-header .bbe-dark-mode .icon-wrapper.light-icon',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'sticky_dark_mode_dark_color'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_dark_mode_dark_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_dark_mode_dark_color' ),
                        'selector'  =>  '.bbe-sticky-header .bbe-dark-mode .icon-wrapper.dark-icon',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'sticky_dark_mode_light_background'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_dark_mode_light_background' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_dark_mode_light_background' ),
                        'selector'  =>  '.bbe-light .bbe-sticky-header .bbe-dark-mode .icon-wrapper.light-icon, .bbe-light .bbe-sticky-header .bbe-dark-mode.layout--two .icon-wrapper.light-icon',
                        'hover_selector'  =>  '.bbe-light .bbe-sticky-header .bbe-dark-mode .icon-wrapper.light-icon, .bbe-light .bbe-sticky-header .bbe-dark-mode.layout--two',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                    'sticky_dark_mode_dark_background' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'sticky_dark_mode_dark_background' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'sticky_dark_mode_dark_background' ),
                        'selector'  =>  '.bbe-dark .bbe-sticky-header .bbe-dark-mode .icon-wrapper.dark-icon, .bbe-dark .bbe-sticky-header .bbe-dark-mode.layout--two .icon-wrapper.dark-icon',
                        'hover_selector'  =>  '.bbe-dark .bbe-sticky-header.site-header .bbe-dark-mode .icon-wrapper.dark-icon, .bbe-dark .bbe-sticky-header .bbe-dark-mode.layout--two',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                ];
                return $dynamic_args;
            }

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