<?php
    /**
     * Block Title 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 function esc_html__;

    if( ! class_exists( __NAMESPACE__ . '\\Block_Title' ) ) {
        /**
         * Block_Title class
         */
        class Block_Title extends Section {
            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-block-title';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'block_title_section' );
                $this->add_control( 'block_title_section_tab' );
                $this->add_control( 'block_title_layouts' );
                $this->add_control( 'block_title_alignment' );
                $this->tab = 'design';
                $this->add_control( 'block_title_typography' );
                $this->add_control( 'block_title_color' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'block_title_section_tab' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'block_title_layouts' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_image' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'block_title_alignment' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'block_title_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'block_title_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 = [
                    'block_title_section' =>  [
                        'title' =>  esc_html__( 'Block Title', 'blog-bee' ),
                        'panel' =>  'global_panel',
                        'priority'  =>  30
                    ],
                    'block_title_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'    =>  Helpers::get_customizer_section_tabs()
                    ],
                    'block_title_layouts' =>  [
                        'label' =>  esc_html__( 'Layouts', 'blog-bee' ),
                        'type'  =>  'radio-image',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Layout 1', 'blog-bee' ),
                                'value' =>  'one',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/block-title-one.webp'
                            ],
                            [
                                'label' =>  esc_html__( 'Layout 2', 'blog-bee' ),
                                'value' =>  'four',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/block-title-four.webp'
                            ],
                        ]
                    ],
                    'block_title_alignment' =>  [
                        'label' =>  esc_html__( 'Alignment', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'fields'    =>  Helpers::get_customizer_alignments()
                    ],
                    'block_title_typography' =>  [
                        'label' =>  esc_html__( 'Typography', 'blog-bee' ),
                        'type'  =>  'typography',
                    ],
                    'block_title_color' =>  [
                        'label' =>  esc_html__( 'Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'color_types'   =>  [ 'solid', 'gradient' ]
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'block_title_section_tab' =>  'general',
                    'block_title_layouts' =>  'one',
                    'block_title_typography'    =>  $this->get_typography( [
                        'font_weight' =>  '700',
                        'font_size' =>  $this->get_responsive( '18px', '18px', '18px' ),
                        'text_transform' =>  'uppercase'
                    ] ),
                    'block_title_color' =>  $this->get_color( [ 'value' => '#30344b' ] ),
                    'block_title_alignment' =>  'left'
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'block_title_layouts'    =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'block-title--'
                    ],
                    'block_title_alignment'    =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'block-align--'
                    ],
                    'block_title_typography'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'block_title_typography' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'block_title_typography' ),
                        'selector'  =>  'body .section-head span.label, body .widget-title span.label, .widget_search .wp-block-search__label, .widget .wp-block-heading',
                    ],
                    'block_title_color' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'block_title_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'block_title_color' ),
                        'selector'  =>  '.bbe-light .section-head > span.label, .bbe-light .widget-title > span.label, .widget_search .wp-block-search__label, .widget .wp-block-heading',
                        'property'  =>  '--bbe-site-color'
                    ],
                ];
                return $dynamic_args;
            }

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