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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'card_settings_section' );
                $this->add_control( 'card_settings_section_tab' );
                $this->add_control( 'card_settings_container' );
                $this->add_control( 'card_settings_animation' );
                $this->tab = 'design';
                $this->add_control( 'card_settings_border' );
                $this->add_control( 'card_settings_border_radius' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'card_settings_section_tab' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'card_settings_container' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'card_settings_animation' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_toggle' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'card_settings_border' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_border' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'card_settings_border_radius' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_dimension' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'card_settings_section' =>  [
                        'title' =>  esc_html__( 'Card Settings', 'blog-bee' ),
                        'priority'  =>  30,
                    ],
                    'card_settings_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'    =>  Helpers::get_customizer_section_tabs()
                    ],
                    'card_settings_container' =>  [
                        'label' =>  esc_html__( 'Container', 'blog-bee' ),
                        'type'  =>  'radio-image',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Unboxed', 'blog-bee' ),
                                'value' =>  'unboxed',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/unboxed.webp'
                            ],
                            [
                                'label' =>  esc_html__( 'Section Boxed', 'blog-bee' ),
                                'value' =>  'section-boxed',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/section-boxed.webp'
                            ],
                            [
                                'label' =>  esc_html__( 'Item Boxed', 'blog-bee' ),
                                'value' =>  'boxed',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/item-boxed.webp'
                            ]
                        ]
                    ],
                    'card_settings_animation' =>  [
                        'label' =>  esc_html__( 'Enable Animation', 'blog-bee' ),
                        'type'  =>  'toggle-button',
                        'conditions'    =>  [
                            'relation'  =>  'AND',
                            'rules' =>  [
                                [
                                    'setting'   =>  'card_settings_container',
                                    'operator'  =>  '==',
                                    'value' =>  'boxed'
                                ]
                            ]
                        ]
                    ],
                    'card_settings_border' =>  [
                        'label' =>  esc_html__( 'Border', 'blog-bee' ),
                        'type'  =>  'border',
                        'color_types'   =>  [ 'solid', 'gradient' ]
                    ],
                    'card_settings_border_radius' =>  [
                        'label' =>  esc_html__( 'Border Radius', 'blog-bee' ),
                        'type'  =>  'dimension',
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'card_settings_section_tab' =>  'general',
                    'card_settings_container' =>  'unboxed',
                    'card_settings_animation' =>  false,
                    'card_settings_border' =>  $this->get_border( [ 'style' =>  'solid', 'color' => '#feeaec' ] ),
                    'card_settings_border_radius' =>  $this->get_dimension( [
                        'top'       =>  0,
                        'right'     =>  0,
                        'bottom'    =>  0,
                        'left'      =>  0,
                    ] ),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'card_settings_container'   =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'card--'
                    ],
                    'card_settings_animation'   =>  [
                        'selector'  =>  'body',
                        'on'    =>  'card-animation--on',
                    ],
                    'card_settings_border'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'card_settings_border' ),
                        'default' =>  Theme_Defaults::get_defaults( 'card_settings_border' ),
                        'selector'  =>  'body',
                        'property'  =>  '--bbe-card-border'
                    ],
                    'card_settings_border_radius'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'card_settings_border_radius' ),
                        'default' =>  Theme_Defaults::get_defaults( 'card_settings_border_radius' ),
                        'selector'  =>  'body',
                        'property'  =>  '--bbe-card-border-radius'
                    ],
                ];
                return $dynamic_args;
            }

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