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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'seo_misc_section' );
                $this->add_control( 'seo_misc_enable_schema' );
                $this->add_control( 'seo_misc_date_to_display' );
                $this->add_control( 'seo_misc_date_format' );
                $this->add_control( 'seo_misc_enable_admin_notices' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'seo_misc_enable_schema' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_toggle' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'seo_misc_date_to_display' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'seo_misc_date_format' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'seo_misc_enable_admin_notices' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_toggle' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'seo_misc_section' =>  [
                        'title' =>  esc_html__( 'SEO / Misc', 'blog-bee' ),
                        'panel' =>  'global_panel',
                        'priority'  =>  10
                    ],
                    'seo_misc_enable_schema' =>  [
                        'label' =>  esc_html__( 'Make website schema ready', 'blog-bee' ),
                        'type'  =>  'toggle-button',
                    ],
                    'seo_misc_date_to_display' =>  [
                        'label' =>  esc_html__( 'Date to Display', 'blog-bee' ),
                        'description' =>  esc_html__( 'Whether to show published date or modified date.', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Published Date', 'blog-bee' ),
                                'value' =>  'published'
                            ],
                            [
                                'label' =>  esc_html__( 'Modified Date', 'blog-bee' ),
                                'value' =>  'modified'
                            ],
                        ]
                    ],
                    'seo_misc_date_format' =>  [
                        'label' =>  esc_html__( 'Date format', 'blog-bee' ),
                        'description' =>  esc_html__( 'Date format applied to single and archive pages.', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'   =>  [
                            'theme_format'  =>  esc_html__( 'Default by theme', 'blog-bee' ),
                            'default'   =>  esc_html__( 'WordPress default date', 'blog-bee' ),
                        ]
                    ],
                    'seo_misc_enable_admin_notices' =>  [
                        'label' =>  esc_html__( 'Disable admin notices', 'blog-bee' ),
                        'description'   =>  esc_html__( 'This will hide all the notices or any message shown by the theme like review notices, change log notices in admin dashboard.', 'blog-bee' ),
                        'type'  =>  'toggle-button',
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'seo_misc_enable_schema' =>  true,
                    'seo_misc_date_to_display'  =>  'published',
                    'seo_misc_date_format'  =>  'default',
                    'seo_misc_enable_admin_notices' =>  true
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args() {
                $dynamic_css = [
                    'seo_misc_date_to_display'  =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'show-date--'
                    ],
                ];
                return $dynamic_css;
            }

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