<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * Customize Base control class.
 *
 * @package pawfect
 * @see     WP_Customize_Control
 * @access  public
 */

// Exit if WP_Customize_Control doesn't exist
if (!class_exists('WP_Customize_Control')) {
    return;
}

/**
 * Class pawfect_Customize_Base_Control
 */
class pawfect_Customize_Base_Control extends WP_Customize_Control {

	/**
	 * Enqueue scripts all controls.
	 */
	public function enqueue() {
		// Color picker alpha
		wp_enqueue_script('wp-color-picker-alpha', PAWFECT_THEME_URL . '/inc/customizer/assets/js/wp-color-picker-alpha.js', array('wp-color-picker'), '1.0.0', true);
		
		// Customizer extensions
		wp_enqueue_script('pawfect-extend-customizer', PAWFECT_THEME_URL . '/inc/customizer/assets/js/extend-customizer.js', array('jquery'), false, true);
		wp_enqueue_style('pawfect-extend-customizer', PAWFECT_THEME_URL . '/inc/customizer/assets/css/extend-customizer.css');

		// Main control scripts
		wp_enqueue_script('pawfect-controls', PAWFECT_THEME_URL . '/inc/customizer/assets/js/controls.js', array('jquery', 'customize-base', 'wp-color-picker-alpha'), false, true);
		wp_enqueue_style('pawfect-controls', PAWFECT_THEME_URL . '/inc/customizer/assets/css/controls.css');
	}

	/**
	 * Refresh the parameters passed to the JavaScript via JSON.
	 */
	public function to_json() {
		parent::to_json();

		$this->json['default'] = $this->setting->default;
		if (isset($this->default)) {
			$this->json['default'] = $this->default;
		}

		$this->json['id']      = $this->id;
		$this->json['value']   = $this->value();
		$this->json['choices'] = $this->choices;
		$this->json['link']    = $this->get_link();
		$this->json['l10n']    = $this->l10n();

		$this->json['inputAttrs'] = '';
		foreach ($this->input_attrs as $attr => $value) {
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr($value) . '" ';
		}
	}

	/**
	 * Don't override render_content() - let WordPress handle default controls
	 * Only custom controls that provide content_template() should override this
	 */

	/**
	 * Empty content template - override in subclasses that use JavaScript templates
	 */
	protected function content_template() {}

	/**
	 * Returns translation strings - override in subclasses
	 */
	protected function l10n() {
		return array();
	}

}
