<?php
/**
 * WARNING:DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * Renders custom range image control type for WP Customizer.
 *
 * @package CR_Login_Page_UI_Customizer
 * @author Aniket Ashtikar
 */

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

/**
 *
 * Class CRLPUIC_Range_Control renders custom range  control type.
 *
 * @since 1.0.0
 */
class CRLPUIC_Range_Control extends WP_Customize_Control {

	/**
	 * The type of customize control being rendered.
	 *
	 * @access public
	 * @since  1.0.0
	 * @var    string
	 */
	public $type = 'crlpuic_range_control';

	/**
	 * Add our JavaScript and CSS to the Customizer.
	 *
	 * @access public
	 * @since  1.0.0
	 */
	public function enqueue() {

		parent::enqueue();

		wp_enqueue_script( 'crlpuic-login-customizer-controls' );
		wp_enqueue_style( 'crlpuic-login-customizer-script' );

	}

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

		parent::to_json();

		// Input attributes.
		$this->json['inputAttrs'] = '';

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

		$this->json['choices'] = wp_parse_args(
			$this->choices,
			array(
				'min'     => '100',
				'max'     => '2000',
				'step'    => '10',
				'unit'    => 'px',
				'default' => '1200',
			)
		);

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

	/**
	 * Don't render the content via PHP.  This control is handled with a JS template.
	 *
	 * @since  1.0.0
	 */
	protected function render_content() {

		?>
		<div class="crlpuic-range-control">
			<label><span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span></label>

			<span class="crlpuic-range-slider-reset dashicons dashicons-image-rotate" data-reset="<?php echo esc_attr( $this->input_attrs['default'] ); ?>" title="<?php esc_attr_e( 'Reset to previously saved value', 'login-page-ui-customizer' ); ?>"></span>

			<div class="slider-control-group">
				<div class="crlpuic-range-slider" data-min="<?php echo esc_attr( $this->input_attrs['min'] ); ?>" data-max="<?php echo esc_attr( $this->input_attrs['max'] ); ?>" data-step="<?php echo esc_attr( $this->input_attrs['step'] ); ?>"></div>

				<input id="<?php echo esc_attr( $this->id ); ?>" class="crlpuic-range-control-input" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" type="number" <?php $this->link(); ?> />&nbsp;<?php printf( '%s', $this->input_attrs['unit'] ); // phpcs:disable WordPress.Security.EscapeOutput ?>
			</div>
		</div>
		<?php
	}

	/**
	 * An Underscore (JS) template for this control's content.
	 *
	 * Class variables for this control class are available in the `data` JS object;
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
	 *
	 * @see    WP_Customize_Control::print_template()
	 *
	 * @access protected
	 * @since  1.0.0
	 * @return void
	 */
	protected function content_template() {}
}
