<?php
/**
 * Alpha Color Control for Customizer.
 *
 * @package Wira
 * @since 1.0.0
 */

namespace Wira;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( class_exists( '\WP_Customize_Control' ) && ! class_exists( '\Wira\Alpha_Color_Control' ) ) {

	class Alpha_Color_Control extends \WP_Customize_Control {

		/**
		 * Control type.
		 *
		 * @var string
		 */
		public $type = 'alpha-color';

		/**
		 * Enqueue control scripts/styles.
		 */
		public function enqueue() {
			wp_enqueue_style( 'wp-color-picker' );
			wp_enqueue_script( 'wp-color-picker' );

			$dir = get_template_directory_uri() . '/inc/class/customizer/assets/alpha-color/';
			wp_enqueue_script(
				'wira-alpha-color-control',
				$dir . 'alpha-color-control.js',
				array( 'jquery', 'wp-color-picker' ),
				'1.0.0',
				true
			);
			wp_enqueue_style(
				'wira-alpha-color-control',
				$dir . 'alpha-color-control.css',
				array(),
				'1.0.0'
			);
		}

		/**
		 * Render control content.
		 */
		public function render_content() {
			if ( empty( $this->label ) ) {
				return;
			}
			?>
			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
			<input
				type="text"
				class="alpha-color-control"
				data-alpha="true"
				data-default-color="<?php echo esc_attr( $this->value() ); ?>"
				<?php $this->link(); ?>
			/>
			<?php
		}
	}
}
