<?php
/**
 * Glides Theme Customizer.
 *
 * @package Glides
 */

 if ( ! class_exists( 'Glides_Customizer' ) ) {

	/**
	 * Customizer Loader
	 *
	 * @since 1.0.0
	 */
	class Glides_Customizer {

		/**
		 * Instance
		 *
		 * @access private
		 * @var object
		 */
		private static $instance;

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

		/**
		 * Constructor
		 */
		public function __construct() {
			/**
			 * Customizer
			 */
			add_action( 'customize_preview_init',                  array( $this, 'glides_customize_preview_js' ) );
			add_action( 'customize_controls_enqueue_scripts',      array( $this, 'glides_controls_scripts' ) );
			add_action( 'customize_controls_enqueue_scripts', 	   array( $this, 'glides_customizer_script' ) );
			add_action( 'customize_register',                      array( $this, 'glides_customizer_register' ) );
			add_action( 'after_setup_theme',                       array( $this, 'glides_customizer_settings' ) );
			
		}
		
		
		/**
		 * Add postMessage support for site title and description for the Theme Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
		 */
		function glides_customizer_register( $wp_customize ) {
			
			$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
			$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
			$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
			$wp_customize->get_setting( 'background_color' )->transport = 'postMessage';
			$wp_customize->get_setting('custom_logo')->transport = 'refresh';

			/**
			 * Register controls
			 */
			$wp_customize->register_control_type( 'Glides_Control_Sortable' );
			$wp_customize->register_control_type( 'Glides_Customizer_Range_Control' );
			
			/**
			 * Helper files
			 */
			require GLIDES_PARENT_INC_DIR . '/customizer/customizer-controls.php';
			require GLIDES_PARENT_INC_DIR . '/customizer/sanitization.php';
		}
		/**
		 * Customizer Controls
		 *
		 * @since 1.0.0
		 * @return void
		 */
		function glides_controls_scripts() {
				$js_prefix  = '.js';
				$css_prefix = '.css';
				
			// Customizer Core.
			wp_enqueue_script( 'glides-customizer-controls-toggle-js', GLIDES_PARENT_INC_URI . '/customizer/assets/js/customizer-toggle-control' . $js_prefix, array(), GLIDES_THEME_VERSION, true );
			// Customizer Controls.
			wp_enqueue_script( 'glides-customizer-controls-js', GLIDES_PARENT_INC_URI . '/customizer/assets/js/customizer-control' . $js_prefix, array( 'glides-customizer-controls-toggle-js' ), GLIDES_THEME_VERSION, true );
		}

		/**
		 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
		 */
		function glides_customize_preview_js() {
			wp_enqueue_script( 'glides-customizer', GLIDES_PARENT_INC_URI . '/customizer/assets/js/customizer-preview.js', array( 'customize-preview' ), '20151215', true );
		}
		
		function glides_customizer_script() {
			 wp_enqueue_script( 'glides-customizer-section', GLIDES_PARENT_INC_URI .'/customizer/assets/js/customizer-section.js', array("jquery"),'', true  );	
		}

		// Include customizer customizer settings.
			
		function glides_customizer_settings() {
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-header.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-slider.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-funfact.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-service.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-feature.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-blog.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-footer.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-page-templates.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-general.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/customizer-options/glides-sidebar.php';
				require GLIDES_PARENT_INC_DIR . '/customizer/glides-premium.php';
		}

	}
}// End if().

/**
 *  Kicking this off by calling 'get_instance()' method
 */
Glides_Customizer::get_instance();