<?php
    /**
     * Widget Area 2 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 function esc_html__;
    use function is_active_sidebar;
    use function esc_attr;
    use function dynamic_sidebar;

    if( ! class_exists( __NAMESPACE__ . '\\Footer_Widget_Area_Two' ) ) {
        /**
         * Footer_Widget_Area_Two class
         */
        class Footer_Widget_Area_Two extends Section {
            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-footer-widget-area-two';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'footer_widget_area_two_section' );
                $this->add_control( 'footer_widget_area_two_redirect' );
                $this->add_control( 'footer_widget_area_two_heading_typography' );
                $this->add_control( 'footer_widget_area_two_content_typography' );
                $this->add_control( 'footer_widget_area_two_heading_color' );
                $this->add_control( 'footer_widget_area_two_content_color' );
                $this->add_control( 'footer_widget_area_two_link_color' );
                $this->add_control( 'footer_widget_area_two_margin' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'footer_widget_area_two_redirect' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_widget_area_two_heading_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_widget_area_two_content_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_widget_area_two_heading_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_widget_area_two_content_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_widget_area_two_link_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_widget_area_two_margin' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_dimension' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'footer_widget_area_two_section' =>  [
                        'title' =>  esc_html__( 'Footer Widget Area 2', 'blog-bee' ),
                        'active_callback'   =>  function(){
                            return Helpers::is_widget_in_builder( 'footer_builder', 'footer-widget-area-two' );
                        },
                        'section_to_open' =>  'footer_builder_section'
                    ],
                    'footer_widget_area_two_redirect' =>  [
                        'label' =>  esc_html__( 'Edit Footer Widget Area 2', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'sidebar-widgets-bbe-footer-widget-area-two'
                    ],
                    'footer_widget_area_two_heading_typography' =>  [
                        'label' =>  esc_html__( 'Heading Typography', 'blog-bee' ),
                        'type'  =>  'typography'
                    ],
                    'footer_widget_area_two_content_typography' =>  [
                        'label' =>  esc_html__( 'Content Typography', 'blog-bee' ),
                        'type'  =>  'typography'
                    ],
                    'footer_widget_area_two_heading_color' =>  [
                        'label' =>  esc_html__( 'Heading Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                    ],
                    'footer_widget_area_two_content_color' =>  [
                        'label' =>  esc_html__( 'Content Color', 'blog-bee' ),
                        'type'  =>  'bbe-color'
                    ],
                    'footer_widget_area_two_link_color' =>  [
                        'label' =>  esc_html__( 'Link Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true
                    ],
                    'footer_widget_area_two_margin' =>  [
                        'label' =>  esc_html__( 'Margin', 'blog-bee' ),
                        'type'  =>  'dimension'
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'footer_widget_area_two_redirect'   =>  '',
                    'footer_widget_area_two_heading_typography' =>  $this->get_typography( [
                        'font_weight'  =>  '700',
                        'font_size'   =>  $this->get_responsive( '18px', '18px', '18px' ),
                        'line_height' =>  $this->get_responsive( 1.4, 1.4, 1.4 ),
                        'text_transform'    =>  'uppercase'
                    ] ),
                    'footer_widget_area_two_content_typography' =>  $this->get_typography( [
                        'font_weight' => 'regular',
                        'font_size'   =>  $this->get_responsive( '15px', '15px', '15px' ),
                    ] ),
                    'footer_widget_area_two_heading_color'  =>  $this->get_color( [ 'value' => '#30344b' ] ),
                    'footer_widget_area_two_content_color'  =>  $this->get_color( [ 'value' => '#30344b' ] ),
                    'footer_widget_area_two_link_color' =>  [
                        'initial'   =>  $this->get_color( [ 'value' => '#0073aa' ] ),
                        'hover'   =>  $this->get_color( [ 'value' => '#E78371' ] ),
                    ],
                    'footer_widget_area_two_margin' =>  $this->get_dimension(),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                if( ! Helpers::is_widget_in_builder( 'footer_builder', 'footer-widget-area-two' ) ) return [];
                $dynamic_args = [
                    'footer_widget_area_two_heading_typography'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_widget_area_two_heading_typography' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_widget_area_two_heading_typography' ),
                        'selector'  =>  '.bbe-footer .bbe-footer-widget-area-two .widget h1.wp-block-heading, .bbe-footer .bbe-footer-widget-area-two .widget h1.widget-title .label, .bbe-footer .bbe-footer-widget-area-two .widget h2.wp-block-heading, .bbe-footer .bbe-footer-widget-area-two .widget h2.widget-title .label, .bbe-footer .bbe-footer-widget-area-two .widget h3.wp-block-heading, .bbe-footer .bbe-footer-widget-area-two .widget h3.widget-title .label, .bbe-footer .bbe-footer-widget-area-two .widget h4.wp-block-heading, .bbe-footer .bbe-footer-widget-area-two .widget h4.widget-title .label, .bbe-footer .bbe-footer-widget-area-two .widget h5.wp-block-heading, .bbe-footer .bbe-footer-widget-area-two .widget h5.widget-title .label, .bbe-footer .bbe-footer-widget-area-two .widget h6.wp-block-heading, .bbe-footer .bbe-footer-widget-area-two .widget h6.widget-title .label',
                    ],
                    'footer_widget_area_two_content_typography'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_widget_area_two_content_typography' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_widget_area_two_content_typography' ),
                        'selector'  =>  'body .bbe-footer .bbe-footer-widget-area-two .widget',
                    ],
                    'footer_widget_area_two_heading_color'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_widget_area_two_heading_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_widget_area_two_heading_color' ),
                        'selector'  =>  '.bbe-light .bbe-footer .bbe-footer-widget-area-two .widget h1, .bbe-light .bbe-footer .bbe-footer-widget-area-two .widget h2, .bbe-light .bbe-footer .bbe-footer-widget-area-two .widget h3, .bbe-light .bbe-footer .bbe-footer-widget-area-two .widget h4, .bbe-light .bbe-footer .bbe-footer-widget-area-two .widget h5, .bbe-light .bbe-footer .bbe-footer-widget-area-two .widget h6',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'footer_widget_area_two_content_color'   =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_widget_area_two_content_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_widget_area_two_content_color' ),
                        'selector'  =>  '.bbe-light .bbe-footer .bbe-footer-widget-area-two .widget',
                        'property'  =>  '--bbe-site-excerpt-color'
                    ],
                    'footer_widget_area_two_link_color'   =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_widget_area_two_link_color' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_widget_area_two_link_color' ),
                        'selector'  =>  'body.bbe-light .site .bbe-footer .bbe-footer-widget-area-two .widget a',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'footer_widget_area_two_margin' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_widget_area_two_margin' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_widget_area_two_margin' ),
                        'selector'  =>  '.bbe-footer-widget-area-two',
                        'property'  =>  'margin'
                    ],
                ];
                return $dynamic_args;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                if( ! is_active_sidebar( self::$id ) ) return;
                
                $block_class[] = self::$id;

                ?>
                    <div class="<?php echo esc_attr( implode( ' ', $block_class ) ); ?>">
                        <?php
                            dynamic_sidebar( self::$id );
                        ?>
                    </div><!-- .bbe-footer-widget-area-two -->
                <?php
            }
        }
        Footer_Widget_Area_Two::get_instance();
    }