<?php

namespace ThemeAtelier\DomainForSale\Frontend\Templates;

use ThemeAtelier\DomainForSale\Frontend\Helpers\Helpers;

class Template_01
{

	public static function content($template_options)
	{
		$options = get_option('dfs-opt');
		$dfs_formTitle            = isset($options['dfs-formtitle']) ? $options['dfs-formtitle'] : '';
		$price_currency  		= isset($options['price_currency']) ? $options['price_currency'] : '';

		Helpers::ShortCodeScripts($template_options);
		// Page options
		$dfs_domainName       = isset($template_options['domain_name']) ? $template_options['domain_name'] : '';
		$price_options 	  = isset($template_options['price_options']) ? $template_options['price_options'] : '';
		$price_tag = isset($template_options['price_tag']) ? $template_options['price_tag'] : '';
		$offer_tag = isset($template_options['offer_tag']) ? $template_options['offer_tag'] : '';
		$sell_price = isset($template_options['sell_price']) ? $template_options['sell_price'] : '';
		$dfs_saleTitle        = isset($template_options['sale_title']) ? $template_options['sale_title'] : '';
		$dfs_sale_content     = isset($template_options['sale_content']) ? $template_options['sale_content'] : '';
		$dfs_contact_title    = isset($template_options['contact_title']) ? $template_options['contact_title'] : '';

		$dfs_background          = isset($template_options['dfs-background']) ? $template_options['dfs-background'] : '';
		$dfs_background_url      = ! empty($dfs_background['background-image']['url']) ? $dfs_background['background-image']['url'] : DOMAIN_FOR_SALE_DIR_URL . 'src/Frontend/assets/images/hero-1.webp';
		$dfs_background_repeat   = isset($dfs_background['background-repeat']) ? $dfs_background['background-repeat'] : '';
		$dfs_background_position = isset($dfs_background['background-position']) ? $dfs_background['background-position'] : '';
		$dfs_background_size     = isset($dfs_background['background-size']) ? $dfs_background['background-size'] : '';
		$color_scheme_type   = isset($template_options['color_scheme_type']) ? $template_options['color_scheme_type'] : 'pre_defined';

		$color_scheme                  = isset($template_options['color_scheme']) ? $template_options['color_scheme'] : '';
		$custom_scheme           = isset($template_options['custom_scheme']) ? $template_options['custom_scheme'] : array();
		$custom_scheme_primary   = ! empty($custom_scheme['primary']) ? $custom_scheme['primary'] : '';
		$custom_scheme_secondary = ! empty($custom_scheme['secondary']) ? $custom_scheme['secondary'] : '';

		if ('pre_defined' === $color_scheme_type) {
			if ($color_scheme === '4') {
				$primary   = '#1abc9c';
				$secondary = '#199e83';
			} elseif ($color_scheme === '1') {
				$primary   = '#44dc46';
				$secondary = '#3bbf3d';
			} elseif ($color_scheme === '2') {
				$primary   = '#C57229';
				$secondary = '#9B1210';
			} elseif ($color_scheme === '3') {
				$primary   = '#e74c3c';
				$secondary = '#d21414';
			} else {
				$primary   = '#1abc9c';
				$secondary = '#199e83';
			}
		} else {
			$primary   = $custom_scheme_primary;
			$secondary = $custom_scheme_secondary;
		}

		$container_width     = isset($template_options['container_width']) ? $template_options['container_width'] : '1140';
		$dfs_gap                 = isset($template_options['dfs_gap']) ? $template_options['dfs_gap'] : '';
		$dfs_overlay             = isset($template_options['dfs-overlay']) ? $template_options['dfs-overlay'] : 'rgba(0,0,0,0.7)';
		$body_typo         = isset($template_options['body_typo']) ? $template_options['body_typo'] : '';
		$body_font_family        = ! empty($body_typo['font-family']) ? $body_typo['font-family'] : 'Nunito';
		$body_font_weight        = ! empty($body_typo['font-weight']) ? $body_typo['font-weight'] : 'normal';
		$body_font_style         = ! empty($body_typo['font-style']) ? $body_typo['font-style'] : 'normal';
		$body_text_transform     = ! empty($body_typo['text-transform']) ? $body_typo['text-transform'] : 'none';
		$body_font_size          = ! empty($body_typo['font-size']) ? $body_typo['font-size'] : '16';
		$body_line_height        = ! empty($body_typo['line-height']) ? $body_typo['line-height'] : '20';
		$body_tablet_font_size   = ! empty($body_typo['tablet-font-size']) ? $body_typo['tablet-font-size'] : '16';
		$body_tablet_line_height = ! empty($body_typo['tablet-line-height']) ? $body_typo['tablet-line-height'] : '20';
		$body_mobile_font_size   = ! empty($body_typo['mobile-font-size']) ? $body_typo['mobile-font-size'] : '16';
		$body_mobile_line_height = ! empty($body_typo['mobile-line-height']) ? $body_typo['mobile-line-height'] : '20';

		$options_data = array(
			'domain_name' => $dfs_domainName,
			'sel_price' => $sell_price,
			'price_currency' => $price_currency,
		);
?>
		<div class="dfs bg--overlay"
			data-template='<?php echo esc_attr(json_encode($options_data)); ?>'
			style="
		--primary: <?php echo esc_attr($primary); ?>;
		--secondary: <?php echo esc_attr($secondary); ?>;
		--dfs_container_width: <?php echo esc_attr($container_width . 'px'); ?>;
		--dfs_gap: <?php echo esc_attr($dfs_gap . 'px'); ?>;
		--background_image: url('<?php echo esc_attr($dfs_background_url); ?>');
		--background_repeat: <?php echo esc_attr($dfs_background_repeat); ?>;
		--background_position: <?php echo esc_attr($dfs_background_position); ?>;
		--background_size: <?php echo esc_attr($dfs_background_size); ?>;
		--dfs_overlay: <?php echo esc_attr($dfs_overlay); ?>;
		--body_font_family: <?php echo esc_attr($body_font_family); ?>;
		--body_font_weight: <?php echo esc_attr($body_font_weight); ?>;
		--body_font_style: <?php echo esc_attr($body_font_style); ?>;
		--body_text_transform: <?php echo esc_attr($body_text_transform); ?>;
		--body_font_size: <?php echo esc_attr($body_font_size . 'px'); ?>;
		--body_line_height: <?php echo esc_attr($body_line_height . 'px'); ?>;
		--body_tablet_font_size: <?php echo esc_attr($body_tablet_font_size . 'px'); ?>;
		--body_tablet_line_height: <?php echo esc_attr($body_tablet_line_height . 'px'); ?>;
		--body_mobile_font_size: <?php echo esc_attr($body_mobile_font_size . 'px'); ?>;
		--body_mobile_line_height: <?php echo esc_attr($body_mobile_line_height . 'px'); ?>;       
		">
			<div class="dfs__container">
				<div class="dfs__wrapper">
					<div class="dfs__content">
						<?php if ($price_options === 'fixed_price' && $price_tag && $sell_price) : ?>
							<div class="dfs__price">
								<p><?php echo wp_kses_post(Helpers::dfs_dynamic_variables($price_tag, array(), '', array(), $sell_price, $price_currency)); ?></p>
							</div>
						<?php
						endif;
						if ($dfs_domainName) :
							include Helpers::dfs_locate_template('item/domain_name.php');
						endif;
						if ($dfs_saleTitle) :
							include Helpers::dfs_locate_template('item/sale_title.php');
						endif;
						if ($dfs_sale_content) :
							include Helpers::dfs_locate_template('item/content.php');
						endif;
						if ($dfs_contact_title) :
							include Helpers::dfs_locate_template('item/contact_info.php');
						endif;
						?>
					</div>
				</div>
				<div class="dfs__wrapper">
					<div class="dfs__contact">
						<?php
						if ($dfs_formTitle) :
							include Helpers::dfs_locate_template('item/form_title.php');
						endif;
						echo wp_kses_post( (string) Helpers::dfs_html_form_code($template_options) );
						?>
					</div>
				</div>
			</div>
		</div>
<?php
	}
}
