<?php
    /**
     * Category colors 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 esc_attr;

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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'category_colors_section' );
                $this->add_control( 'category_colors_style' );
                $this->add_control( 'category_colors_typography' );
                $this->add_control( 'category_colors_color' );
                $this->add_control( 'category_colors_background' );
                $this->add_control( 'category_colors_border_color' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'category_colors_style' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_multiselect' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'category_colors_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'category_colors_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'category_colors_background' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'category_colors_border_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 = [
                    'category_colors_section' =>  [
                        'title' =>  esc_html__( 'Category Colors', 'blog-bee' ),
                        'panel'  =>  'colors_panel'
                    ],
                    'category_colors_style' =>  [
                        'label' =>  esc_html__( 'Style', 'blog-bee' ),
                        'type'  =>  'multiselect',
                        'fields'    =>  Helpers::get_customizer_icon_style()
                    ],
                    'category_colors_typography' =>  [
                        'label' =>  esc_html__( 'Typography', 'blog-bee' ),
                        'type'  =>  'typography'
                    ],
                    'category_colors_color' =>  [
                        'label' =>  esc_html__( 'Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true
                    ],
                    'category_colors_background' =>  [
                        'label' =>  esc_html__( 'Background', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                        'color_types'   =>  [ 'solid', 'gradient' ]
                    ],
                    'category_colors_border_color' =>  [
                        'label' =>  esc_html__( 'Border Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_hover' =>  true,
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'category_colors_style' => '',
                    'category_colors_typography' => $this->get_typography([
                        'font_weight'   =>  '700',
                        'font_size' =>  $this->get_responsive( '11px', '11px', '11px' ),
                        'line_height' =>  $this->get_responsive( 1.3, 1.3, 1.3 ),
                        'letter_spacing'    =>  $this->get_responsive( '0.05em', '0.05em', '0.05em' ),
                        'text_transform'    =>  'uppercase'
                    ]),
                    'category_colors_color' => [
                        'initial'   =>  $this->get_color( [ 'value' => '#6b727e' ] ),
                        'hover' =>  $this->get_color()
                    ],
                    'category_colors_background' => [
                        'initial'   =>  $this->get_color( [ 'value' => '#f5f5f5' ] ),
                        'hover' =>  $this->get_color( [ 'value' => '#fff' ] )
                    ],
                    'category_colors_border_color' => [
                        'initial'   =>  $this->get_color( [ 'value' => '#000' ] ),
                        'hover' =>  $this->get_color( [ 'value' => '#000' ] )
                    ],
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'category_colors_typography'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'category_colors_typography' ),
                        'default' =>  Theme_Defaults::get_defaults( 'category_colors_typography' ),
                        'selector'  =>  'body .site .entry-categories .cat-item, body .site .entry-categories .cat-item .cat-item-link'
                    ],
                    'category_colors_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'category_colors_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'category_colors_color' ),
                        'selector'  =>  'body.bbe-light .entry-categories .cat-item a',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'category_colors_background'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'category_colors_background' ),
                        'default' =>  Theme_Defaults::get_defaults( 'category_colors_background' ),
                        'selector'  =>  'body.bbe-light.cat-filled .entry-categories .cat-item a',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                    'category_colors_border_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'category_colors_border_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'category_colors_border_color' ),
                        'selector'  =>  'body.bbe-light.cat-outline .entry-categories .cat-item a',
                        'property'  =>  '--bbe-site-border-color'
                    ],
                ];
                return $dynamic_args;
            }

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