<?php
    /**
     * Typography 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__ . '\\Typography' ) ) {
        /**
         * Typography class
         */
        class Typography extends Section {
            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-typography';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'typography';
                $this->add_section( 'typography_section' );
                $this->add_control( 'typography_section_tab' );
                $this->add_control( 'base_typography' );
                $this->add_control( 'headings_typography' );
                $this->add_control( 'meta_typography' );
                $this->tab = 'icon-picker';
                $this->add_control( 'meta_seperator_icon' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'typography_section_tab' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'base_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'headings_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'meta_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'meta_seperator_icon' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'typography_section' =>  [
                        'title' =>  esc_html__( 'Typography & Icon Picker', 'blog-bee' ),
                        'priority' =>  30,
                    ],
                    'typography_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Typography', 'blog-bee' ),
                                'value' =>  'typography'
                            ],
                            [
                                'label' =>  esc_html__( 'Icon Picker', 'blog-bee' ),
                                'value' =>  'icon-picker'
                            ],
                        ]
                    ],
                    'base_typography'    =>  [
                        'label' =>  esc_html__( 'Base Typography', 'blog-bee' ),
                        'description'   =>  esc_html__( 'Targets everything that is not meta, post title and headings.', 'blog-bee' ),
                        'type'  =>  'typography'
                    ],
                    'headings_typography'    =>  [
                        'label' =>  esc_html__( 'Heading Typography', 'blog-bee' ),
                        'description'   =>  esc_html__( 'Targets everything all heading H1 - H6.', 'blog-bee' ),
                        'type'  =>  'typography'
                    ],
                    'meta_typography'    =>  [
                        'label' =>  esc_html__( 'Meta Typography', 'blog-bee' ),
                        'description'   =>  esc_html__( 'Targets date, author, comments and read time.', 'blog-bee' ),
                        'type'  =>  'typography'
                    ],
                    'meta_seperator_icon'    =>  [
                        'label' =>  esc_html__( 'Meta Seperator', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'   =>  [
                            'none'  =>  esc_html__( 'None', 'blog-bee' ),
                            'circle'    =>  esc_html__( 'Circle', 'blog-bee' ),
                            'dot'   =>  esc_html__( 'Dot', 'blog-bee' ),
                            'dash'  =>  esc_html__( 'Dash', 'blog-bee' ),
                            'slash' =>  esc_html__( 'Slash', 'blog-bee' ),
                            'pipe'  =>  esc_html__( 'Pipe', 'blog-bee' ),
                        ]
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'typography_section_tab' =>  'typography',
                    'base_typography'    =>  $this->get_typography( [
                        'font_weight'   =>  'regular',
                        'font_size' =>    $this->get_responsive( '14px', '14px', '14px' ),
                        'line_height' =>    $this->get_responsive( 1.64, 1.64, 1.64 ),
                    ] ),
                    'headings_typography'    =>  $this->get_typography( [
                        'font_weight'   =>  '600',
                        'font_size' =>    $this->get_responsive( '18px', '18px', '18px' )
                    ] ),
                    'meta_typography'    =>  $this->get_typography( [
                        'font_weight'   =>  '500',
                        'font_size' =>    $this->get_responsive( '11px', '11px', '11px' ),
                        'letter_spacing'    =>  $this->get_responsive( '0.02em', '0.02em', '0.02em' ),
                        'text_transform'   =>  'uppercase'
                    ] ),
                    'meta_seperator_icon'  =>  'none',
                    'meta_icon_picker_heading_toggle'  =>  false,
                    'date_icon_picker'  =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-calendar' ] ),
                    'author_icon_picker'    =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-user' ] ),
                    'comment_icon_picker'   =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-comments' ] ),
                    'read_time_icon_picker' =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-clock' ] ),
                    'post_format_icon_picker_heading_toggle'    =>  false,
                    'audio_icon_picker' =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-headphones' ] ),
                    'gallery_icon_picker'   =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-images' ] ),
                    'image_icon_picker' =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-image' ] ),
                    'quote_icon_picker' =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-quote-left' ] ),
                    'standard_icon_picker'  =>  $this->get_icon_picker( [ 'type' => 'none' ] ),
                    'video_icon_picker' =>  $this->get_icon_picker( [ 'value' => 'fa-solid fa-video' ] ),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'meta_seperator_icon'    =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'meta-seperator--'
                    ],
                    'base_typography'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'base_typography' ),
                        'default' =>  Theme_Defaults::get_defaults( 'base_typography' ),
                        'selector'  =>  'body .bbe-article .entry-excerpt p, .page-content .error-desc, body .site .author-desc, .archive-description p'
                    ],
                    'headings_typography'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'headings_typography' ),
                        'default' =>  Theme_Defaults::get_defaults( 'headings_typography' ),
                        'selector'  =>  'body.single .site-main .wp-block-heading, .page-header .page-title, body.page .site-main .wp-block-heading'
                    ],
                    'meta_typography'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'meta_typography' ),
                        'default' =>  Theme_Defaults::get_defaults( 'meta_typography' ),
                        'selector'  =>  'body .site .bbe-article .entry-meta > div, body .widget .bbe-article .entry-date'
                    ],
                ];
                return $dynamic_args;
            }

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