<?php
    /**
     * Header first row section
     * 
     * @package Blog Bee
     * @since 1.0.0
     */
    namespace BBE\Customizer\Section;

    use BBE\Helpers as Helpers;
    use BBE\Customizer\Section\Section as Section;
    use BBE\Customizer\Theme_Defaults as Theme_Defaults;
    use BBE\Customizer\Section\Header_Builder as Header_Builder;

    use function esc_html__;


    if( ! class_exists( __NAMESPACE__ . '\\Header_Top_Row' ) ) {
        /**
         * Header_Top_Row Class
         */
        class Header_Top_Row extends Section {
            /**
             * Section id
             * 
             * @since 1.0.0 
             */
            public static $id = 'bbe-header-top-row';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'header_top_row_section' );
                $this->add_control( 'header_top_row_full_width' );
                $this->add_control( 'header_top_row_background' );
                $this->add_control( 'header_top_row_border' );
                $this->add_control( 'header_top_row_padding' );

            }

            /**
             * Settings
             * 
             * @param string $id    The setting id
             * @since 1.0.0
             */
            public function get_settings( $id = '' ): array {
                $settings = [
                    'header_top_row_full_width' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'header_top_row_background'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'header_top_row_border'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_border' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'header_top_row_padding'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_dimension' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @param string    $id     The control id
             * @since 1.0.0
             */
            public function get_controls( $id = '' ): array {
                $controls = [
                    'header_top_row_section' =>  [
                        'title' =>  esc_html__( 'Header Top Row', 'blog-bee' ),
                        'section_to_open' =>  'header_builder_section'
                    ],
                    'header_top_row_full_width' =>  [
                        'label' =>  esc_html__( 'Width', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Full Width', 'blog-bee' ),
                                'value' =>  'on'
                            ],
                            [
                                'label' =>  esc_html__( 'Boxed', 'blog-bee' ),
                                'value' =>  'off'
                            ],
                        ]
                    ],
                    'header_top_row_background' =>  [
                        'label' =>  esc_html__( 'Background', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'color_types'   =>  [ 'solid', 'gradient', 'image' ]
                    ],
                    'header_top_row_border' =>  [
                        'label' =>  esc_html__( 'Border', 'blog-bee' ),
                        'type'  =>  'border'
                    ],
                    'header_top_row_padding' =>  [
                        'label' =>  esc_html__( 'Padding', 'blog-bee' ),
                        'type'  =>  'dimension',
                        'responsive'    =>  true
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Set defaults
             * 
             * @since 1.0.0
             * 
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'header_top_row_full_width' =>  'on',
                    'header_top_row_background' =>  $this->get_color( [ 'value' => '' ] ),
                    'header_top_row_border' =>  $this->get_border( [
                        'width'   =>    [ 'top' => 0, 'right' => 0, 'bottom' => 1, 'left' => 0, 'link' => false ],
                        'color'   =>    '#efefef',
                        'style'   =>    'solid'
                    ] ),
                    'header_top_row_padding'    =>  $this->get_responsive(
                        $this->get_dimension( [ 'top' => 8, 'bottom' => 8, 'link' => false ] ),
                        $this->get_dimension( [ 'top' => 8, 'bottom' => 8, 'link' => false ] ),
                        $this->get_dimension( [ 'top' => 8, 'bottom' => 8, 'link' => false ] )
                    ),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_css_args = [
                    'header_top_row_full_width' =>  [
                        'selector'  =>  '.bbe-header-top-row',
                        'prefix'    =>  'full-width--'
                    ],
                    'header_top_row_background' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'header_top_row_background' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'header_top_row_background' ),
                        'selector'  =>  '.bbe-light .bbe-header .bbe-header-top-row.full-width--off .row, .bbe-light .bbe-header .bbe-header-top-row.full-width--on',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                    'header_top_row_border' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'header_top_row_border' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'header_top_row_border' ),
                        'selector'  =>  'body .bbe-header .bbe-header-top-row.full-width--off .row, body .bbe-header .bbe-header-top-row.full-width--on'
                    ],
                    'header_top_row_padding'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'header_top_row_padding' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'header_top_row_padding' ),
                        'selector'  =>  'body .bbe-header .bbe-header-top-row.full-width--off .row, body .bbe-header .bbe-header-top-row.full-width--on',
                        'property'  =>  'padding'
                    ],
                ];
                return $dynamic_css_args;
            }

            /**
             * Render html
             * 
             * @since 1.0.0
             */
            public function render_html() {}
        }
        Header_Top_Row::get_instance();
    }