<?php
/**
 * Customize Color control class.
 *
 * @package paws-and-care
 *
 * @see     WP_Customize_Control
 * @access  public
 */

/**
 * Class Paws_And_Care_Customize_Color_Control
 */
class Paws_And_Care_Customize_Color_Control extends Paws_And_Care_Customize_Base_Control {

	/**
	 * Backwards compatibility.
	 *
	 * @access protected
	 * @var bool
	 */
	protected $alpha = false;

	/**
	 * Customize control type.
	 *
	 * @access public
	 * @var    string
	 */
	public $type = 'paws-and-care-color';

	/**
	 * Colorpicker palette
	 *
	 * @access public
	 * @var bool
	 */
	public $palette = true;

	/**
	 * Mode.
	 *
	 * @var string
	 */
	public $mode = 'full';

	/**
	 * Some fields require options to be set.
	 * We're whitelisting the property here
	 * and suggest you validate this in a child class.
	 *
	 * @access protected
	 * @var array
	 */
	public $choices = array();

	/**
	 * Render the control's content.
	 */
	protected function render_content() {
		$alpha = ( isset( $this->choices['alpha'] ) && $this->choices['alpha'] ) ? 'true' : 'false';
		?>
		<label>
			<?php if ( ! empty( $this->label ) ) : ?>
				<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
			<?php endif; ?>
			<?php if ( ! empty( $this->description ) ) : ?>
				<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
			<?php endif; ?>
		</label>
		<input type="text"
			class="paws-and-care-color-control"
			data-id="<?php echo esc_attr( $this->id ); ?>"
			data-type="<?php echo esc_attr( $this->mode ); ?>"
			data-palette="<?php echo esc_attr( $this->palette ? 'true' : 'false' ); ?>"
			data-default-color="<?php echo esc_attr( $this->setting->default ); ?>"
			data-alpha="<?php echo esc_attr( $alpha ); ?>"
			value="<?php echo esc_attr( $this->value() ); ?>"
			<?php $this->link(); ?>
		/>
		<?php
	}

	/**
	 * Refresh the parameters passed to the JavaScript via JSON.
	 *
	 * @see    WP_Customize_Control::to_json()
	 * @access public
	 * @return void
	 */
	public function to_json() {

		parent::to_json();

		$this->json['palette']          = $this->palette;
		$this->json['choices']['alpha'] = ( isset( $this->choices['alpha'] ) && $this->choices['alpha'] ) ? 'true' : 'false';
		$this->json['mode']             = $this->mode;

	}
}
