<?php
/**
 * Customise Control Label Class
 *
 * @package errigal
 * @since 1.1.0
 */

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Shared\{
	Errigal_Html_Builder as Html_Builder,
	Errigal_Validator as Validator,
};
use WP_Customize_Control;

/**
 * Customise Label Control Class.
 *
 * @since 1.1.0
 *
 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/
 */
class Errigal_Customise_Control_Label extends WP_Customize_Control {
	/**
	 * Control type.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public $type = 'errigal-label';

	/**
	 * Renders control's content.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/render_content/
	 *
	 * @return void
	 */
	public function render_content() {
		$html_builder = Html_Builder::create();

		if ( Validator::is_non_empty_string( $this->label ) ) {
			$html_builder->create_span(
				array(
					Html_Option::ATTRS => array(
						Html_Attr::CLASS_NAME => 'customize-control-title',
					),
				)
			)->render_element(
				esc_html( $this->label )
			);
		}

		if ( Validator::is_non_empty_string( $this->description ) ) {
			$html_builder->create_span(
				array(
					Html_Option::ATTRS => array(
						Html_Attr::ID         => '_customize-description-' . $this->id,
						Html_Attr::CLASS_NAME => array(
							'description',
							'customize-control-description',
						),
					),
				)
			)->render_element(
				esc_html( $this->description )
			);
		}
	}
}
