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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'website_layout_section' );
                $this->add_control( 'site_container_section_tab' );
                $this->add_control( 'site_container_width' );
                $this->add_control( 'site_content_width' );
                $this->tab = 'design';
                $this->add_control( 'site_image_radius' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'site_container_width' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_image' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'site_container_section_tab' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'site_content_width' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_range' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'site_image_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 = '' ) {
                $boxed_condition = [
                    'relation' => 'AND',
                    'rules' =>  [
                        [
                            'setting' =>  'site_container_width',
                            'operator' =>  '==',
                            'value' =>  'two'
                        ]
                    ]
                ];
                $controls = [
                    'website_layout_section' =>  [
                        'title' =>  esc_html__( 'Website Layout', 'blog-bee' ),
                        'panel' =>  'global_panel',
                        'priority'  =>  30
                    ],
                    'site_container_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'    =>  Helpers::get_customizer_section_tabs()
                    ],
                    'site_container_width' =>  [
                        'label' =>  esc_html__( 'Website Layout', 'blog-bee' ),
                        'type'  =>  'radio-image',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Full Width', 'blog-bee' ),
                                'value' =>  'one',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/full-width.webp'
                            ],
                            [
                                'label' =>  esc_html__( 'Boxed', 'blog-bee' ),
                                'value' =>  'two',
                                'url'   =>  get_template_directory_uri() . '/inc/customizer/assets/images/boxed.webp'
                            ],
                        ]
                    ],
                    'site_content_width' =>  [
                        'label' =>  esc_html__( 'Content Width', 'blog-bee' ),
                        'type'  =>  'bbe-number',
                        'responsive'    =>  true,
                        'input_attrs'   =>  [
                            'px' =>  [
                                'min'   =>  100,
                                'max'   =>  2000,
                                'step'  =>  1
                            ]
                        ],
                        'conditions'    =>  [
                            'relation' => 'AND',
                            'rules' =>  [
                                [
                                    'setting' =>  'site_container_width',
                                    'operator' =>  '==',
                                    'value' =>  'one'
                                ]
                            ]
                        ]
                    ],
                    'site_image_radius' =>  [
                        'label' =>  esc_html__( 'Image 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( [
                    'site_container_section_tab' =>  'general',
                    'site_container_width' =>  'one',
                    'site_content_width' =>  $this->get_responsive( '1340px', '1340px', '1340px' ),
                    'site_image_radius' =>  $this->get_dimension(),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'site_container_width'    =>  [
                        'selector' =>  'body',
                        'prefix' =>  'width-layout--',
                    ],
                    'site_content_width'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'site_content_width' ),
                        'default' =>  Theme_Defaults::get_defaults( 'site_content_width' ),
                        'selector' =>  '.bbe-container',
                        'property' =>  'max-width',
                    ],
                    'site_image_radius'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'site_image_radius' ),
                        'default' =>  Theme_Defaults::get_defaults( 'site_image_radius' ),
                        'selector' =>  'body',
                        'property' =>  '--bbe-image-border-radius',
                    ],
                ];
                return $dynamic_args;
            }

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