<?php
/**
 * Upgrade-to-Pro Customizer section.
 *
 * @package ttsunsolar
 */

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

/**
 * Pro upgrade section type.
 */
if ( class_exists( 'WP_Customize_Section' ) ) {

	/**
	 * Customizer pro upgrade section.
	 */
	class Ttsunsolar_Customize_Section_Pro extends WP_Customize_Section {

		/**
		 * Type.
		 *
		 * @var string
		 */
		public $type = 'ttsunsolar-section-pro';

		/**
		 * Button label.
		 *
		 * @var string
		 */
		public $pro_text = '';

		/**
		 * Button URL.
		 *
		 * @var string
		 */
		public $pro_url = '';

		/**
		 * JSON data for JS.
		 *
		 * @return array
		 */
		public function json() {
			$json             = parent::json();
			$json['pro_text'] = $this->pro_text;
			$json['pro_url']  = esc_url( $this->pro_url );
			return $json;
		}

		/**
		 * Underscore template.
		 */
		protected function render_template() {
			?>
			<li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
				<h3 class="accordion-section-title">
					{{ data.title }}
					<# if ( data.pro_text && data.pro_url ) { #>
						<a href="{{ data.pro_url }}" class="button button-primary" target="_blank" rel="noopener noreferrer">{{ data.pro_text }}</a>
					<# } #>
				</h3>
			</li>
			<?php
		}
	}
}
