<?php
if (!get_theme_mod('events_and_celebrations_enable_banner_section', false)) {
	return;
}

/**
 * Render Banner Section.
 */
$events_and_celebrations_banner_section_title = get_theme_mod('events_and_celebrations_banner_section_title', '');
$events_and_celebrations_banner_section_description = get_theme_mod('events_and_celebrations_banner_section_description', '');
$events_and_celebrations_button_label = get_theme_mod('events_and_celebrations_banner_button_label_', '');
$events_and_celebrations_button_link = get_theme_mod('events_and_celebrations_banner_button_link_', '');
$events_and_celebrations_banner_section_image = get_theme_mod('events_and_celebrations_banner_section_image');

$events_and_celebrations_default_image_url = get_template_directory_uri() . '/resource/img/default1.png';
$events_and_celebrations_banner_bg = !empty($events_and_celebrations_banner_section_image) ? $events_and_celebrations_banner_section_image : $events_and_celebrations_default_image_url;

$events_and_celebrations_primary_button_href = !empty($events_and_celebrations_button_link) ? $events_and_celebrations_button_link : '#';
$events_and_celebrations_secondary_button_href = !empty($events_and_celebrations_secondary_button_link) ? $events_and_celebrations_secondary_button_link : '#';
?>
<section id="events_and_celebrations_banner_section" class="sale-banner sale-banner--modern"
	style="background-image: url('<?php echo esc_url($events_and_celebrations_banner_bg); ?>');">
	<div class="sale-banner__container">
		<div class="sale-banner__inner">
			<div class="sale-banner__content">
				<?php if (!empty($events_and_celebrations_banner_section_title)): ?>
					<h1 class="sale-banner__title"><?php echo esc_html($events_and_celebrations_banner_section_title); ?></h1>
				<?php endif; ?>

				<?php if (!empty($events_and_celebrations_banner_section_description)): ?>
					<p class="sale-banner__description">
						<?php echo esc_html($events_and_celebrations_banner_section_description); ?></p>
				<?php endif; ?>

				<?php if (!empty($events_and_celebrations_button_label)): ?>
					<div class="sale-banner__actions">
						<?php if (!empty($events_and_celebrations_button_label)): ?>
							<?php if (empty($events_and_celebrations_button_link)): ?>
								<a href="<?php echo esc_url($events_and_celebrations_primary_button_href); ?>"
									class="sale-banner__button sale-banner__button--primary is-disabled" aria-disabled="true">
									<?php echo esc_html($events_and_celebrations_button_label); ?>
								</a>
							<?php else: ?>
								<a href="<?php echo esc_url($events_and_celebrations_primary_button_href); ?>"
									class="sale-banner__button sale-banner__button--primary">
									<?php echo esc_html($events_and_celebrations_button_label); ?>
								</a>
							<?php endif; ?>
						<?php endif; ?>

						<?php if (get_theme_mod('events_and_celebrations_banner_secondary_button_label') != '' || get_theme_mod('events_and_celebrations_banner_secondary_button_link') != '') { ?>
							<!-- Button to open the modal -->
							<a id="openModalButton"
								data-modal-src="<?php echo esc_url(get_theme_mod('events_and_celebrations_banner_secondary_button_link')); ?>"
								class="video-btn" href="#"><i class="fas fa-play me-2"></i>
								<?php esc_html_e(get_theme_mod('events_and_celebrations_banner_secondary_button_label')); ?>
							</a>
						<?php } ?>
					</div>

					<?php
					$events_and_celebrations_features = array();

					for ($events_and_celebrations_i = 1; $events_and_celebrations_i <= 4; $events_and_celebrations_i++) {
						$events_and_celebrations_features[] = array(
							'icon' => get_theme_mod('events_and_celebrations_banner_feature_icon_' . $events_and_celebrations_i),
							'title' => get_theme_mod('events_and_celebrations_banner_feature_title_' . $events_and_celebrations_i),
						);
					}
					?>

					<?php if (array_filter($events_and_celebrations_features)): ?>

						<div class="sale-banner-features">

							<?php for ($events_and_celebrations_i = 1; $events_and_celebrations_i <= 4; $events_and_celebrations_i++):

								$events_and_celebrations_icon = get_theme_mod('events_and_celebrations_banner_feature_icon_' . $events_and_celebrations_i, 'fas fa-star');
								$events_and_celebrations_title = get_theme_mod('events_and_celebrations_banner_feature_title_' . $events_and_celebrations_i);

								if (empty($events_and_celebrations_title)) {
									continue;
								}
								?>

								<div class="feature-item">

									<div class="feature-icon">
										<i class="<?php echo esc_attr($events_and_celebrations_icon); ?>"></i>
									</div>

									<h5 class="feature-title">
										<?php echo esc_html($events_and_celebrations_title); ?>
									</h5>

								</div>

							<?php endfor; ?>

						</div>

					<?php endif; ?>
				<?php endif; ?>
			</div>
		</div>
	</div>
</section>

<!-- The modal -->
<div id="myModal" class="modal">
	<!-- Modal content -->
	<div class="modal-content">
		<span id="closeModalButton" class="close">&times;</span>
		<?php if (get_theme_mod('events_and_celebrations_banner_secondary_button_link') != '') { ?>
			<embed id="videoPlayer" height="369"
				src="<?php echo esc_url(get_theme_mod('events_and_celebrations_banner_secondary_button_link')); ?>"
				allow="accelerometer; autoplay; classipboard-write; encrypted-media; gyroscope; picture-in-picture"
				allowfullscreen></embed>
		<?php } else { ?>
			<h3><?php esc_html_e('Add Video Url In Customizer To Display Video Here', 'events-and-celebrations'); ?>
			</h3>
		<?php } ?>
	</div>
</div>