<?php
/**
 * Blogbuster Theme Customizer
 *
 * @package Blogbuster
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function blogbuster_customize_register( $wp_customize ) {

	require get_template_directory(). '/inc/customizer/override-defaults.php';

	require get_template_directory(). '/inc/customizer/custom-controls/register-custom-controls.php';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'blogbuster_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'blogbuster_customize_partial_blogdescription',
			)
		);
	}
}
add_action( 'customize_register', 'blogbuster_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function blogbuster_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function blogbuster_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function blogbuster_customize_preview_js() {
	wp_enqueue_script( 'blogbuster-google-webfont', get_template_directory_uri() . '/inc/customizer/custom-controls/typography/webfontloader.js', array( 'jquery' ) );
	
	wp_enqueue_script( 'blogbuster-customizer', get_template_directory_uri() . '/inc/customizer/assets/js/customizer-preview.js', array( 'customize-preview' ), BLOGBUSTER_VERSION, true );
}
add_action( 'customize_preview_init', 'blogbuster_customize_preview_js' );

	if ( ! function_exists( 'blogbuster_customize_backend_scripts' ) ) :

        /**
         * Enqueue required scripts and styles for the customizer panel.
         *
         * @since 1.0.0
         */
        function blogbuster_customize_backend_scripts() {

            wp_enqueue_style( 'select2', get_template_directory_uri() . '/assets/library/select2/css/select2.css', null );

            wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/assets/library/font-awesome/css/all.min.css', array(), '6.5.1' );

            wp_enqueue_style( 'mt-extend-customizer', get_template_directory_uri() . '/inc/customizer/assets/css/extend-customizer.css', array(), BLOGBUSTER_VERSION );

            wp_enqueue_style( 'mt-custom-control-styles', get_template_directory_uri() . '/inc/customizer/assets/css/custom-control-styles.css', array(), BLOGBUSTER_VERSION );

            wp_enqueue_script( 'select2', get_template_directory_uri() . '/assets/library/select2/js/select2.js', array( 'jquery' ), '4.0.13', true );

            wp_enqueue_script( 'mt-extend-customizer', get_template_directory_uri(). '/inc/customizer/assets/js/extend-customizer.js', array('jquery'), BLOGBUSTER_VERSION, true );

            wp_enqueue_script( 'blogbuster-control-dependency', get_template_directory_uri() . '/inc/customizer/assets/js/control-dependency.js', array( 'jquery', 'customize-controls' ), '1.0.0', true );
            
		    wp_enqueue_script( 'mt-custom-control-scripts', get_template_directory_uri() . '/inc/customizer/assets/js/custom-control-scripts.js', array( 'jquery', 'customize-controls', 'customize-base', 'select2' ), BLOGBUSTER_VERSION, true );
            
        }

    endif;

    add_action( 'customize_controls_enqueue_scripts', 'blogbuster_customize_backend_scripts', 10 );


/*----------------------------- load required files ------------------------------------------------*/
	
	require get_template_directory(). '/inc/customizer/extend-customizer/class-customize-panel.php';
	require get_template_directory(). '/inc/customizer/extend-customizer/class-customize-section.php';
	
	require get_template_directory(). '/inc/customizer/customizer-callback.php';
	require get_template_directory(). '/inc/customizer/customizer-selective-refresh.php';
	require get_template_directory(). '/inc/customizer/customizer-sanitize.php';
	require get_template_directory(). '/inc/customizer/customizer-helper.php';

	require get_template_directory(). '/inc/customizer/register-panels-sections.php';

	$blogbuster_sections_array = array(
		'general'		=> array( 'site-style', 'preloader', 'social-icon', 'sidebar', 'colors', 'typography', 'scroll-top', 'performance' ),
		'header'		=> array( 'site-identity', 'main-area', ),
		'frontpage'		=> array( 'featured', 'sticky-posts' ),
		'innerpage'		=> array( 'archive', 'posts' ),
		'footer'		=> array( 'main-area', 'bottom-area' )
	);

	foreach ( $blogbuster_sections_array as $key => $value ) {
		foreach ( $value as $k => $v ) {
			require get_template_directory() . '/inc/customizer/sections/'. $key . '/' . $v .'.php';
		}
	}