<?php
/**
 * Blog Over Customizer Tabs Control.
 * 
 * Displays General / Design tabs to organize customizer settings.
 *
 * @package Blog_Over
 */

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

if (!class_exists('WP_Customize_Control')) {
    return;
}

if (!class_exists('blog_over_Customizer_Control_Tabs')):
    /**
     * Tabs control class.
     */
    class blog_over_Customizer_Control_Tabs extends WP_Customize_Control
    {
        /**
         * The control type.
         *
         * @var string
         */
        public $type = 'blog-over-tabs';

        /**
         * Enqueue control related scripts/styles.
         */
        public function enqueue()
        {
            wp_enqueue_style(
                'blog-over-tabs-control',
                get_template_directory_uri() . '/assets/css/customizer-tabs.css',
                array(),
                time() // Cache buster
            );

            wp_enqueue_script(
                'blog-over-tabs-control',
                get_template_directory_uri() . '/assets/js/customizer-tabs.js',
                array('jquery', 'customize-controls'),
                time(), // Cache buster
                true
            );
        }

        /**
         * Refresh the parameters passed to the JavaScript via JSON.
         */
        public function to_json()
        {
            parent::to_json();
            $this->json['id'] = $this->id;
        }

        /**
         * An Underscore (JS) template for this control's content.
         */
        protected function content_template()
        {
            ?>
            <div class="blog-over-tabs-wrapper" id="blog-over-tabs-{{ data.id }}">
                <div class="blog-over-tabs-controls">
                    <button type="button" class="blog-over-tab-btn active" data-tab="general">
                        <?php esc_html_e('GENERAL', 'blog-over'); ?>
                    </button>
                    <button type="button" class="blog-over-tab-btn" data-tab="design">
                        <?php esc_html_e('DESIGN', 'blog-over'); ?>
                    </button>
                </div>
            </div>
            <?php
        }
    }
endif;

add_action('customize_register', function($wp_customize) {
    $wp_customize->register_control_type('blog_over_Customizer_Control_Tabs');
});
