<?php
    /**
     * Header shortcode 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;
    use function do_shortcode;

    if( ! class_exists( __NAMESPACE__ . '\\Header_Shortcode_One' ) ) {
        /**
         * Header_Shortcode_One class
         */
        class Header_Shortcode_One extends Section {
            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-header-shortcode-1';

            /**
             * Is section active
             * 
             * @since 1.0.0
             */
            private function is_active(): bool {
                $header_builder = Helpers::is_widget_in_builder( 'header_builder', 'header-shortcode-1' );
                $header_responsive_builder = Helpers::is_widget_in_builder( 'header_responsive_builder', 'header-shortcode-1' );
                return ( $header_builder || $header_responsive_builder );
            }

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'header_shortcode_one_section' );
                $this->add_control( 'header_shortcode_one_shortcode_field' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'header_shortcode_one_shortcode_field' =>  [
                        'sanitize_callback' =>  'sanitize_text_field',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ]
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'header_shortcode_one_section' =>  [
                        'title' =>  esc_html__( 'Header Shortcode 1', 'blog-bee' ),
                        'active_callback'   =>  function(){
                            return $this->is_active();
                        },
                        'section_to_open' =>  'header_builder_section'
                    ],
                    'header_shortcode_one_shortcode_field' =>  [
                        'label' =>  esc_html__( 'Shortcode', 'blog-bee' ),
                        'type'  =>  'bbe-text',
                    ]
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'header_shortcode_one_shortcode_field'    =>  '',
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                if( ! $this->is_active() ) return [];
                return [];
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                $block_class[] = self::$id;

                ?>
                    <div class="<?php echo esc_attr( implode( ' ', $block_class ) ); ?>">
                        <?php
                            echo do_shortcode( Theme_Defaults::get_theme_option( 'header_shortcode_one_shortcode_field' ) );
                        ?>
                    </div><!-- .bbe-header-shortcode-1 -->
                <?php
            }
        }
        Header_Shortcode_One::get_instance();
    }