<?php
/**
 * Acoustics Theme Customizer
 *
 *
 * @author      CodeGearThemes
 * @category    WordPress
 * @package     Acoustics
 * @version     1.0.0
 *
 */

if ( !class_exists( 'Acoustics_Customizer' ) ) {
	class Acoustics_Customizer {

		/**
		 * Instance
		 */
		private static $instance;

		/**
		 * Initiator
		 */
		public static function get_instance() {
			if ( ! isset( self::$instance ) ) {
				self::$instance = new self;
			}
			return self::$instance;
		}


		/**
		 * Constructor
		 */
		public function __construct() {
			add_action( 'customize_register', array( $this, 'acoustics_customize_register' ) );
			add_action( 'customize_preview_init', array( $this, 'acoustics_customize_preview_script' ) );
			add_action( 'customize_controls_print_footer_scripts', array( $this, 'acoustics_scripts' ) );
		}

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

			// @codingStandardsIgnoreStart WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
			require get_template_directory() . '/includes/customizer/controls/message/class-control-message.php';
			require get_template_directory() . '/includes/customizer/controls/premium/class-control-premium.php';
			require get_template_directory() . '/includes/customizer/controls/color-group/class-control-color-group.php';
			require get_template_directory() . '/includes/customizer/controls/radio-buttons/class-control-radio-buttons.php';
			require get_template_directory() . '/includes/customizer/controls/dimensions/class-control-dimensions.php';
			require get_template_directory() . '/includes/customizer/controls/radio-image/class-control-radio-image.php';
			require get_template_directory() . '/includes/customizer/controls/divider/class-control-divider.php';
			require get_template_directory() . '/includes/customizer/controls/class-control-section-title.php';
			require get_template_directory() . '/includes/customizer/controls/slider/class-control-slider.php';
			require get_template_directory() . '/includes/customizer/controls/switch/class-control-switch.php';
			require get_template_directory() . '/includes/customizer/controls/heading/class-control-heading.php';
			require get_template_directory() . '/includes/customizer/controls/typography/class-control-typography.php';
			require get_template_directory() . '/includes/customizer/controls/alpha-color/class-control-alpha-color.php';
			require get_template_directory() . '/includes/customizer/controls/tabs/class-control-tabs.php';
			// @codingStandardsIgnoreEnd WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound

			$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
			$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
			$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

			// @codingStandardsIgnoreStart WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
			require get_template_directory() . '/includes/customizer/sanitizer.php';
			require get_template_directory() . '/includes/customizer/callbacks.php';
			require get_template_directory() . '/includes/customizer/options/general.php';
			require get_template_directory() . '/includes/customizer/options/header.php';
			require get_template_directory() . '/includes/customizer/options/colors.php';
			require get_template_directory() . '/includes/customizer/options/typography.php';
			require get_template_directory() . '/includes/customizer/options/home.php';
			require get_template_directory() . '/includes/customizer/options/performance.php';
			require get_template_directory() . '/includes/customizer/options/footer.php';
			require get_template_directory() . '/includes/customizer/options/layout.php';

			require_once get_template_directory() . '/includes/customizer/options/navigation.php';

			$wp_customize->get_section( 'title_tagline' )->priority		= 1;
			$wp_customize->get_section( 'title_tagline' )->panel 		= 'acoustics_header_panel';

			if ( isset( $wp_customize->selective_refresh ) ) {
				$wp_customize->selective_refresh->add_partial( 'blogname', array(
					'selector'        => '.site-title a',
					'render_callback' => array( $this, 'acoustics_customize_partial_blogname' ),
				) );
				$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
					'selector'        => '.site-description',
					'render_callback' => array( $this, 'acoustics_customize_partial_blogdescription' ),
				) );
			}
		}

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

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

		/**
		 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
		 */
		function acoustics_customize_preview_script() {
			wp_enqueue_script( 'acoustics-customizer-preview', get_template_directory_uri() . '/assets/admin/js/customizer.preview.js', array( 'customize-preview' ), '20151215', true );
		}

		public function acoustics_scripts() {
			wp_enqueue_style( 'acoustics-customizer-styles', get_template_directory_uri() . '/assets/admin/css/customizer.css', array(), ACOUSTICS_VERSION,'all' );
			wp_enqueue_script( 'acoustics-customizer-scripts', get_template_directory_uri() . '/assets/admin/js/customizer.js', array( 'jquery', 'jquery-ui-core' ), ACOUSTICS_VERSION, true );
		}

	}
}
Acoustics_Customizer::get_instance();


