<?php
if ( ! get_theme_mod( 'design_studio_enable_banner_section', false ) ) {
	return;
}
/**
 * Render Banner Section.
*/ 
$design_studio_banner_section_heading = get_theme_mod( 'design_studio_banner_section_heading');
$design_studio_banner_section_content = get_theme_mod( 'design_studio_banner_section_content');
$design_studio_banner_section_description = get_theme_mod( 'design_studio_banner_section_description');
$design_studio_button_label = get_theme_mod( 'design_studio_banner_button_label_');
$design_studio_button_link  = get_theme_mod( 'design_studio_banner_button_link_');
$design_studio_default_image_url = get_template_directory_uri() . '/resource/img/default1.png';
$design_studio_banner_section_image = get_theme_mod( 'design_studio_banner_section_image', $design_studio_default_image_url );

$design_studio_discount      = get_theme_mod( 'design_studio_banner_discount');
$design_studio_discount_lbl  = get_theme_mod( 'design_studio_banner_discount_label');
$design_studio_discount_off  = get_theme_mod( 'design_studio_banner_discount_off');
$design_studio_secondary_stat_label = get_theme_mod( 'design_studio_banner_secondary_stat_label' );

$design_studio_badge_value  = get_theme_mod( 'design_studio_banner_badge_value' );
$design_studio_badge_label  = get_theme_mod( 'design_studio_banner_badge_label' );
$design_studio_badge_plus   = get_theme_mod( 'design_studio_banner_badge_plus', '+' );
$design_studio_badge_images = array();

for ( $i = 1; $i <= 4; $i++ ) {
	$image = get_theme_mod( 'design_studio_banner_badge_image_' . $i );
	if ( ! empty( $image ) ) {
		$design_studio_badge_images[] = $image;
	}
}

$design_studio_banner_image_alt = '';
$design_studio_banner_image_id  = attachment_url_to_postid( $design_studio_banner_section_image );

if ( $design_studio_banner_image_id ) {
	$design_studio_banner_image_alt = get_post_meta( $design_studio_banner_image_id, '_wp_attachment_image_alt', true );
}

if ( empty( $design_studio_banner_image_alt ) ) {
	$design_studio_banner_image_alt = $design_studio_banner_section_heading;
}

$design_studio_has_visual_stats = ! empty( $design_studio_discount_lbl ) || ! empty( $design_studio_discount ) || ! empty( $design_studio_discount_off ) || ! empty( $design_studio_secondary_stat_label );

$design_studio_has_badge = ! empty( $design_studio_badge_value ) 
	|| ! empty( $design_studio_badge_label ) 
	|| ! empty( $design_studio_badge_images );
?>
<section id="design_studio_banner_section" class="fashion-banner sale-banner">
	<div class="asterthemes-wrapper">
		<div class="sale-banner__inner">
			<div class="sale-banner__content banner-content">
				<?php if ( ! empty( $design_studio_banner_section_description ) ) : ?>
					<p class="sale-banner__description"><?php echo esc_html( $design_studio_banner_section_description ); ?></p>
				<?php endif; ?>

				<?php if ( ! empty( $design_studio_button_label ) ) : ?>
					<a href="<?php echo esc_url( $design_studio_button_link ); ?>" class="sale-banner__button banner-btn">
						<?php echo esc_html( $design_studio_button_label ); ?>
					</a>
				<?php endif; ?>
			</div>

			<div class="sale-banner__media" aria-hidden="true">
				<div class="sale-banner__model banner-model">
					<?php if ( $design_studio_banner_image_id ) : ?>
						<?php
						echo wp_get_attachment_image(
							$design_studio_banner_image_id,
							'full',
							false,
							array(
								'class'         => 'sale-banner__model-image',
								'alt'           => esc_attr( $design_studio_banner_image_alt ),
								'loading'       => 'eager',
								'decoding'      => 'async',
								'fetchpriority' => 'high',
							)
						);
						?>
					<?php else : ?>
						<img class="sale-banner__model-image" src="<?php echo esc_url( $design_studio_banner_section_image ); ?>" alt="<?php echo esc_attr( $design_studio_banner_image_alt ); ?>" loading="eager" decoding="async" fetchpriority="high">
					<?php endif; ?>

					<?php if ( ! empty( $design_studio_banner_section_heading ) ) : ?>
						<h1 class="sale-banner__heading sale-title">
							<span class="sale-banner__heading-primary"><?php echo esc_html( $design_studio_banner_section_heading ); ?></span>
							<?php if ( ! empty( $design_studio_banner_section_content ) ) : ?>
								<span class="sale-banner__heading-secondary"><?php echo esc_html( $design_studio_banner_section_content ); ?></span>
							<?php endif; ?>
						</h1>
					<?php endif; ?>

				</div>

				<?php if ( $design_studio_has_badge ) : ?>
					<div class="sale-banner__badge" role="presentation">
						<?php if ( ! empty( $design_studio_badge_value ) ) : ?>
							<strong class="sale-banner__badge-value"><?php echo esc_html( $design_studio_badge_value ); ?></strong>
						<?php endif; ?>

						<?php if ( ! empty( $design_studio_badge_label ) ) : ?>
							<span class="sale-banner__badge-label"><?php echo esc_html( $design_studio_badge_label ); ?></span>
						<?php endif; ?>

						<?php if ( ! empty( $design_studio_badge_images ) ) : ?>
							<div class="sale-banner__badge-media">
								<?php foreach ( $design_studio_badge_images as $image_url ) : ?>
									<img 
										class="sale-banner__badge-avatar"
										src="<?php echo esc_url( $image_url ); ?>"
										alt="<?php esc_attr_e( 'Client avatar', 'design-studio' ); ?>"
									/>
								<?php endforeach; ?>
								<span class="sale-banner__badge-plus sale-banner__badge-avatar" aria-hidden="true"><?php echo esc_html( $design_studio_badge_plus ); ?></span>
							</div>
						<?php endif; ?>

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

			<?php if ( $design_studio_has_visual_stats ) : ?>
				<aside class="sale-banner__visual" aria-label="<?php esc_attr_e( 'Banner statistics', 'design-studio' ); ?>">
					<div class="sale-banner__stat banner-discount">
						<?php if ( ! empty( $design_studio_discount ) ) : ?>
							<h2 class="sale-banner__stat-value"><?php echo esc_html( $design_studio_discount ); ?></h2>
						<?php endif; ?>
						<?php if ( ! empty( $design_studio_discount_lbl ) ) : ?>
							<p class="sale-banner__stat-label"><?php echo esc_html( $design_studio_discount_lbl ); ?></p>
						<?php endif; ?>
					</div>

					<?php if ( ! empty( $design_studio_discount_off ) || ! empty( $design_studio_secondary_stat_label ) ) : ?>
						<div class="sale-banner__stat sale-banner__stat--secondary">
							<?php if ( ! empty( $design_studio_discount_off ) ) : ?>
								<h2 class="sale-banner__stat-value"><?php echo esc_html( $design_studio_discount_off ); ?></h2>
							<?php endif; ?>
							<?php if ( ! empty( $design_studio_secondary_stat_label ) ) : ?>
								<p class="sale-banner__stat-label"><?php echo esc_html( $design_studio_secondary_stat_label ); ?></p>
							<?php endif; ?>
						</div>
					<?php endif; ?>
				</aside>
			<?php endif; ?>
		</div>

	</div>
	<?php if ( ! empty( $design_studio_bottom_text ) ) : ?>
		<div class="sale-banner__bottom banner-bottom-strip">
			<p><?php echo esc_html( $design_studio_bottom_text ); ?></p>
		</div>
	<?php endif; ?>
</section>