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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'footer_divider_one_section' );
                $this->add_control( 'footer_divider_one_section_tab' );
                $this->add_control( 'footer_divider_one_notice' );
                $this->add_control( 'footer_divider_one_style' );
                $this->add_control( 'footer_divider_one_width' );
                $this->add_control( 'footer_divider_one_height' );
                $this->tab = 'design';
                $this->add_control( 'footer_divider_one_color' );
                $this->add_control( 'footer_divider_one_margin' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'footer_divider_one_section_tab' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_divider_one_notice' =>  [
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_divider_one_style' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_divider_one_width' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_range' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_divider_one_height' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_range' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_divider_one_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_divider_one_margin' =>  [
                        '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 = [
                    'footer_divider_one_section' =>  [
                        'title' =>  esc_html__( 'Footer Divider 1', 'blog-bee' ),
                        'active_callback'   =>  function(){
                            return Helpers::is_widget_in_builder( 'footer_builder', 'footer-divider-1' );
                        },
                        'section_to_open' =>  'footer_builder_section'
                    ],
                    'footer_divider_one_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'    =>  Helpers::get_customizer_section_tabs()
                    ],
                    'footer_divider_one_notice' =>  [
                        'label' =>  esc_html__( 'For this widget to work, there has to be atleast 1 other widget in the row. Other divider widgets do not count.', 'blog-bee' ),
                        'type'  =>  'notice',
                    ],
                    'footer_divider_one_style' =>  [
                        'label' =>  esc_html__( 'Style', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Solid', 'blog-bee' ),
                                'value' =>  'solid'
                            ],
                            [
                                'label' =>  esc_html__( 'Dashed', 'blog-bee' ),
                                'value' =>  'dashed'
                            ],
                            [
                                'label' =>  esc_html__( 'Dotted', 'blog-bee' ),
                                'value' =>  'dotted'
                            ],
                            [
                                'label' =>  esc_html__( 'Double', 'blog-bee' ),
                                'value' =>  'double'
                            ],
                        ]
                    ],
                    'footer_divider_one_width' =>  [
                        'label' =>  esc_html__( 'Width', 'blog-bee' ),
                        'type'  =>  'bbe-number',
                        'input_attrs'   =>  [
                            'px'    =>  [
                                'min'   =>  0,
                                'max'   =>  100,
                                'step'  =>  1
                            ]
                        ]
                    ],
                    'footer_divider_one_height' =>  [
                        'label' =>  esc_html__( 'Height', 'blog-bee' ),
                        'type'  =>  'bbe-number',
                        'input_attrs'   =>  [
                            '%'    =>  [
                                'min'   =>  0,
                                'max'   =>  100,
                                'step'  =>  1
                            ]
                        ]
                    ],
                    'footer_divider_one_color' =>  [
                        'label' =>  esc_html__( 'Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                    ],
                    'footer_divider_one_margin' =>  [
                        'label' =>  esc_html__( 'Margin', 'blog-bee' ),
                        'type'  =>  'dimension',
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'footer_divider_one_section_tab' =>  'general',
                    'footer_divider_one_notice' =>  '',
                    'footer_divider_one_style' =>  'solid',
                    'footer_divider_one_width' =>  '1px',
                    'footer_divider_one_height' =>  '50%',
                    'footer_divider_one_color' =>  $this->get_color( [ 'value' => '#30344b' ] ),
                    'footer_divider_one_margin' =>  $this->get_dimension(),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                if( ! Helpers::is_widget_in_builder( 'footer_builder', 'footer-divider-1' ) ) return [];
                $dynamic_args = [
                    'footer_divider_one_style' =>  [
                        'selector' =>  '.bbe-footer-divider-1',
                        'prefix' =>  'style--'
                    ],
                    'footer_divider_one_width' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_divider_one_width' ),
                        'default' =>  Theme_Defaults::get_defaults( 'footer_divider_one_width' ),
                        'selector' =>  '.bbe-footer .bbe-footer-divider-1',
                        'property' =>  'border-right-width'
                    ],
                    'footer_divider_one_height' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_divider_one_height' ),
                        'default' =>  Theme_Defaults::get_defaults( 'footer_divider_one_height' ),
                        'selector' =>  '.bbe-footer .bbe-footer-divider-1',
                        'property' =>  'height'
                    ],
                    'footer_divider_one_color' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_divider_one_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'footer_divider_one_color' ),
                        'selector' =>  '.bbe-light .bbe-footer .bbe-footer-divider-1',
                        'property' =>  '--bbe-site-border-color'
                    ],
                    'footer_divider_one_margin' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_divider_one_margin' ),
                        'default' =>  Theme_Defaults::get_defaults( 'footer_divider_one_margin' ),
                        'selector' =>  '.bbe-footer .bbe-footer-divider-1',
                        'property' =>  'margin'
                    ],
                ];
                return $dynamic_args;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                $block_class[] = self::$id;
                $block_class[] = 'style--' . Theme_Defaults::get_theme_option( 'footer_divider_one_style' );
                $block_class[] = 'bbe-builder-divider';

                ?>
                    <div class="<?php echo esc_attr( implode( ' ', $block_class ) ); ?>"></div>
                <?php
            }
        }
        Footer_Divider_One::get_instance();
    }