<?php
/**
 * Shop Hero Section Template Part
 *
 * Displays the page header for product archives (breadcrumb, title, stat).
 *
 * @package pawwell
 */

defined('ABSPATH') || exit;

// Get current term info.
$term             = get_queried_object();
$term_description = isset($term->description) ? $term->description : '';

// Determine title and description.
if (is_product_category() || is_product_tag()) {
	$page_title = single_term_title('', false);
	$page_desc  = $term_description;
} elseif (is_shop()) {
	$page_title = get_theme_mod( 'pawwell_woo_archive_heading', __( 'Shop', 'pawwell' ) );
	$page_desc  = '';
} else {
	$page_title = __('Products', 'pawwell');
	$page_desc  = '';
}

// Total product count for the stat card.
$total_products = (int) wc_get_loop_prop('total', 0);
$shop_url        = get_permalink(wc_get_page_id('shop'));
?>

<section class="shop-page-title">
	<div class="container">
		<?php if ( pawwell_breadcrumb_is_enabled() ) : ?>
		<nav class="spt-crumb" aria-label="<?php esc_attr_e('Breadcrumb', 'pawwell'); ?>">
			<a href="<?php echo esc_url(home_url('/')); ?>">
				<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 11 12 4l9 7"/><path d="M5 10v10h14V10"/><path d="M10 20v-6h4v6"/></svg>
				<?php esc_html_e('Home', 'pawwell'); ?>
			</a>
			<svg class="sep" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
			<?php
			if (is_product_category()) {
				echo '<a href="' . esc_url($shop_url) . '">' . esc_html__('Shop', 'pawwell') . '</a>';
				echo '<svg class="sep" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>';
				echo '<span class="current">' . esc_html(single_term_title('', false)) . '</span>';
			} elseif (is_shop()) {
				echo '<span class="current">' . esc_html__('Shop All', 'pawwell') . '</span>';
			} else {
				echo '<span class="current">' . esc_html($page_title) . '</span>';
			}
			?>
		</nav>
		<?php endif; ?>

		<div class="spt-row">
			<div class="spt-text">
				<div class="spt-eyebrow"><?php echo esc_html( get_theme_mod( 'pawwell_woo_archive_eyebrow', __( 'The Collection', 'pawwell' ) ) ); ?></div>
				<h1 class="spt-title">
					<?php echo esc_html($page_title); ?>
					<?php if (is_shop()) : ?>
						<span class="spt-accent"><?php echo esc_html( get_theme_mod( 'pawwell_woo_archive_accent', __( 'Products', 'pawwell' ) ) ); ?></span>
					<?php endif; ?>
				</h1>
				<?php if (!empty($page_desc)) : ?>
					<p class="spt-sub"><?php echo esc_html($page_desc); ?></p>
				<?php elseif (is_shop()) : ?>
					<p class="spt-sub"><?php echo esc_html( get_theme_mod( 'pawwell_woo_archive_subheading', __( 'Premium nutrition, vet-approved health supplements, grooming essentials, toys & accessories — curated for every wag, whisker and wing.', 'pawwell' ) ) ); ?></p>
				<?php endif; ?>
			</div>

			<?php if ($total_products > 0 && get_theme_mod( 'pawwell_woo_archive_stat_enable', true )) : ?>
				<div class="spt-stat">
					<div class="spt-stat-icon">
						<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg>
					</div>
					<div class="spt-stat-text">
						<strong><?php echo esc_html(number_format_i18n($total_products)); ?>+</strong>
						<span><?php echo esc_html( get_theme_mod( 'pawwell_woo_archive_stat_text', __( 'products in stock', 'pawwell' ) ) ); ?></span>
					</div>
				</div>
			<?php endif; ?>
		</div>
	</div>
</section>
