<?php
    /**
     * Footer bottom row 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 BBE\Customizer\Section\Footer_Builder as Footer_Builder;

    use function esc_html__;

    if( ! class_exists( __NAMESPACE__ . '\\Footer_Bottom_Row' ) ) {
        /**
         * Footer_Bottom_Row Class
         */
        class Footer_Bottom_Row extends Section {
            /**
             * Section id
             * 
             * @since 1.0.0 
             */
            public static $id = 'bbe-footer-bottom-row';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->add_section( 'footer_bottom_row_section' );
                $this->add_control( 'footer_bottom_row_section_tab' );
                $this->add_control( 'footer_bottom_row_horizontal_alignment' );
                $this->add_control( 'footer_bottom_row_visibility' );
                $this->tab = 'design';
                $this->add_control( 'footer_bottom_row_full_width' );
                $this->add_control( 'footer_bottom_row_background' );
                $this->add_control( 'footer_bottom_row_border' );
                $this->add_control( 'footer_bottom_row_padding' );

            }

            /**
             * Settings
             * 
             * @param string $id    The setting id
             * @since 1.0.0
             */
            public function get_settings( $id = '' ): array {
                $settings = [
                    'footer_bottom_row_section_tab'    =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_bottom_row_horizontal_alignment'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_bottom_row_visibility'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_multiselect' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_bottom_row_full_width' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_radio_tab' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_bottom_row_background'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_bottom_row_border'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_border' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'footer_bottom_row_padding'    =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_dimension' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @param string    $id     The control id
             * @since 1.0.0
             */
            public function get_controls( $id = '' ): array {
                $controls = [
                    'footer_bottom_row_section' =>  [
                        'title' =>  esc_html__( 'Footer Bottom Row', 'blog-bee' ),
                        'section_to_open' =>  'footer_builder_section'
                    ],
                    'footer_bottom_row_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'    =>  Helpers::get_customizer_section_tabs()
                    ],
                    'footer_bottom_row_horizontal_alignment' =>  [
                        'label' =>  esc_html__( 'Horizontal Alignment', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Top', 'blog-bee' ),
                                'value' =>  'top'
                            ],
                            [
                                'label' =>  esc_html__( 'Center', 'blog-bee' ),
                                'value' =>  'center'
                            ],
                            [
                                'label' =>  esc_html__( 'Bottom', 'blog-bee' ),
                                'value' =>  'bottom'
                            ],
                        ]
                    ],
                    'footer_bottom_row_visibility' =>  [
                        'label' =>  esc_html__( 'Visibility', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'multiple'  =>  true,
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Desktop', 'blog-bee' ),
                                'value' =>  'desktop'
                            ],
                            [
                                'label' =>  esc_html__( 'Tablet', 'blog-bee' ),
                                'value' =>  'tablet'
                            ],
                            [
                                'label' =>  esc_html__( 'Mobile', 'blog-bee' ),
                                'value' =>  'mobile'
                            ],
                        ]
                    ],
                    'footer_bottom_row_full_width' =>  [
                        'label' =>  esc_html__( 'Row Full Width', 'blog-bee' ),
                        'type'  =>  'radio-tab',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Full Width', 'blog-bee' ),
                                'value' =>  'on'
                            ],
                            [
                                'label' =>  esc_html__( 'Boxed', 'blog-bee' ),
                                'value' =>  'off'
                            ],
                        ]
                    ],
                    'footer_bottom_row_background' =>  [
                        'label' =>  esc_html__( 'Background', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'color_types'   =>  [ 'solid', 'gradient', 'image' ]
                    ],
                    'footer_bottom_row_border' =>  [
                        'label' =>  esc_html__( 'Border', 'blog-bee' ),
                        'type'  =>  'border'
                    ],
                    'footer_bottom_row_padding' =>  [
                        'label' =>  esc_html__( 'Padding', 'blog-bee' ),
                        'type'  =>  'dimension',
                        'responsive'    =>  true
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Set defaults
             * 
             * @since 1.0.0
             * 
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'footer_bottom_row_section_tab' =>  'general',
                    'footer_bottom_row_direction' =>  'horizontal',
                    'footer_bottom_row_horizontal_alignment' =>  'center',
                    'footer_bottom_row_visibility' =>  'desktop tablet mobile',
                    'footer_bottom_row_full_width' =>  'on',
                    'footer_bottom_row_background' =>  $this->get_color( [ 'value' => '' ] ),
                    'footer_bottom_row_border' =>  $this->get_border(),
                    'footer_bottom_row_padding'    =>  $this->get_responsive(
                        $this->get_dimension( [ 'top' => 50, 'bottom' => 50, 'link' => false ] ),
                        $this->get_dimension( [ 'top' => 50, 'bottom' => 50, 'link' => false ] ),
                        $this->get_dimension( [ 'top' => 50, 'bottom' => 50, 'link' => false ] )
                    ),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_css_args = [
                    'footer_bottom_row_horizontal_alignment' =>  [
                        'selector'  =>  '.bbe-footer-bottom-row',
                        'prefix'    =>  'align--'
                    ],
                    'footer_bottom_row_full_width' =>  [
                        'selector'  =>  '.bbe-footer-bottom-row',
                        'prefix'    =>  'full-width--'
                    ],
                    'footer_bottom_row_background' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_bottom_row_background' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_bottom_row_background' ),
                        'selector'  =>  '.bbe-light .bbe-footer .bbe-footer-bottom-row.full-width--off .row, .bbe-light .bbe-footer .bbe-footer-bottom-row.full-width--on',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                    'footer_bottom_row_border' =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_bottom_row_border' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_bottom_row_border' ),
                        'selector'  =>  '.bbe-footer .bbe-footer-bottom-row.full-width--off .row, .bbe-footer .bbe-footer-bottom-row.full-width--on',
                    ],
                    'footer_bottom_row_padding'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'footer_bottom_row_padding' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'footer_bottom_row_padding' ),
                        'selector'  =>  '.bbe-footer .bbe-footer-bottom-row.full-width--off .row, .bbe-footer .bbe-footer-bottom-row.full-width--on',
                        'property'  =>  'padding'
                    ],
                ];
                return $dynamic_css_args;
            }

            /**
             * Render html
             * 
             * @since 1.0.0
             */
            public function render_html() {
                Footer_Builder::get_instance()->render_row_html( self::$id, 'bottom' );
            }
        }
        Footer_Bottom_Row::get_instance();
    }