<?php
if (! defined('ABSPATH')) {
    exit;
} $data = isset($args['data']) ? $args['data'] : null;

if (! $data || (isset($data->hero_enabled) && ! $data->hero_enabled)) {
    return;
} $show_tags = isset($args['show_tags']) ? (bool) $args['show_tags'] : true; ?>

<section class="blog-hero-section">
	<?php
$is_mobile = wp_is_mobile();
$bg_pc = $data->hero_bg_image;
$bg_mobile = $data->hero_bg_image_mobile;

if ($is_mobile) {
    $image_url = ! empty($bg_mobile) ? $bg_mobile : $bg_pc;
    $image_class = 'hero-bg-image-mobile';
} else {
    $image_url = ! empty($bg_pc) ? $bg_pc : $bg_mobile;
    $image_class = 'hero-bg-image';
} ?>
	<?php if (! empty($image_url)) : ?>
		<img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($data->page_title); ?>" class="<?php echo esc_attr($image_class); ?>" fetchpriority="high" loading="eager" decoding="sync" data-pgo-field="<?php echo $is_mobile ? 'hero-block.bg_image_mobile' : 'hero-block.bg_image'; ?>" />
	<?php endif; ?>
	<div class="hero-overlay"></div>
	<div class="hero-content">
		<?php
$subtitle = $data->is_category_page ? $data->page_description : ($data->page_subtitle ?? '');
puffergo_render_component('hero-text', array('title' => $data->page_title, 'subtitle' => $subtitle, )); ?>

		<?php
$pgo_tag_limit = 8;
$pgo_visible_cats = $show_tags ? array_slice($data->categories, 0, $pgo_tag_limit) : array();
$pgo_overflow_cats = $show_tags ? array_slice($data->categories, $pgo_tag_limit) : array(); ?>
		<?php if ($show_tags && ! empty($pgo_visible_cats)) : ?>
			<div class="hero-filter-tags">
				<?php foreach ($pgo_visible_cats as $cat) : ?>
					<a href="<?php echo esc_url($cat['url']); ?>" class="hero-tag" data-category="<?php echo esc_attr($cat['slug'] ?? ''); ?>">
						<?php echo esc_html($cat['name']); ?>
					</a>
				<?php endforeach; ?>
				<?php if (! empty($pgo_overflow_cats)) : ?>
					<details class="hero-tag-more">
						<summary class="hero-tag" role="button"><?php esc_html_e('More', 'puffergo'); ?></summary>
						<div class="hero-tag-more-panel">
							<?php foreach ($pgo_overflow_cats as $cat) : ?>
								<a href="<?php echo esc_url($cat['url']); ?>" class="hero-tag-more-item" data-category="<?php echo esc_attr($cat['slug'] ?? ''); ?>">
									<?php echo esc_html($cat['name']); ?>
								</a>
							<?php endforeach; ?>
						</div>
					</details>
				<?php endif; ?>
			</div>
		<?php endif; ?>
	</div>
</section>
