<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Kktfwp_Customize_Control_Color' ) && class_exists( 'WP_Customize_Color_Control' ) ) {

	/**
	 * The parent class for all custom controls.
	 * Other controls should extend this object.
	 */
	class Kktfwp_Customize_Control_Color extends WP_Customize_Color_Control {
		
		/**
		 * Used to automatically generate all postMessage scripts.
		 *
		 * @access public
		 * @var array
		 */
		public $js_vars = array();

		/**
		 * Used to automatically generate all CSS output.
		 *
		 * @access public
		 * @var array
		 */
		public $output = array();

		/**
		 * Data type
		 *
		 * @access public
		 * @var string
		 */
		public $option_type = 'theme_mod';
		
		/**
		 * Used to automatically generate all postMessage scripts.
		 *
		 * @access public
		 * @var bool
		 */
		public $auto_preview = false;
		
		/**
		 * Used to automatically check settings state.
		 *
		 * @access public
		 * @var bool
		 */
		public $auto_control = false;

		/**
		 * The config we're using for this control
		 *
		 * @access public
		 * @var string
		 */
		public $kktfwp_config = 'global';

		/**
		 * Constructor.
		 *
		 * Any supplied $args override class property defaults.
		 *
		 * @access public
		 * @param WP_Customize_Manager $manager The WordPress WP_Customize_Manager object.
		 * @param string               $id       A specific ID of the setting. Can be a theme mod or option name.
		 * @param array                $args     Setting arguments.
		 */
		public function __construct( $manager, $id, $args = array() ) {
			parent::__construct( $manager, $id, $args );
			
			// Build an array for postMessage
			$el = $this->json();
			Kktfwp_Customize::$js_controls[$el['id']] = $this->json();
		}			
			
		/**
		 * Refresh the parameters passed to the JavaScript via JSON.
		 *
		 * @since 3.4.0
		 * @uses WP_Customize_Control::to_json()
		 */
		public function to_json() {
			parent::to_json();
			$this->json['js_vars']     = $this->js_vars;
			$this->json['auto_preview']   = $this->auto_preview;
			$this->json['auto_control']   = $this->auto_control;
			$this->json['output']      = $this->output;
			$this->json['id']          = $this->id;
			$this->json['kktfwpConfig'] = $this->kktfwp_config;
		}
		
		/**
		 * Don't render the control content from PHP, as it's rendered via JS on load.
		 *
		 * @since 3.4.0
		 */
		public function render_content() {}
	}
}