<?php
/**
 * ITSWEBER CMS – Default Theme: Gallery Preview Section Template
 * Page Builder section template (3.2.0)
 *
 * Variables: $data (array), $section (DB row), $sectionId (string)
 *
 * @author  Benny Weber
 * @copyright ITSWEBER, www.itsweber.de
 */

if (empty($gallery_preview_albums)) return;

$_show_img_count = !empty($data['show_image_count']);
?>
<section id="<?= e($sectionId) ?>" class="<?= build_section_classes('gallery-preview', $data) ?>">
    <div class="container">
        <h2 class="reveal"><?= e($data['title'] ?? 'Our Work') ?></h2>
        <?php if (!empty($data['subtitle'])): ?>
        <p class="section-subtitle reveal"><?= e($data['subtitle']) ?></p>
        <?php endif; ?>
        <div class="gallery-preview-grid">
            <?php foreach ($gallery_preview_albums as $album): ?>
            <a href="/gallery/<?= e($album['slug']) ?>" class="gallery-preview-card reveal">
                <?php if (!empty($album['cover_image'])): ?>
                <?= picture_tag($album['cover_image'], $album['title'], '', true) ?>
                <?php else: ?>
                <div class="gallery-preview-placeholder"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg></div>
                <?php endif; ?>
                <span><?= e($album['title']) ?><?php if ($_show_img_count && isset($album['image_count'])): ?> <small>(<?= (int)$album['image_count'] ?>)</small><?php endif; ?></span>
            </a>
            <?php endforeach; ?>
        </div>
        <?php if (!empty($data['cta_text'])): ?>
        <p class="gallery-preview-cta">
            <a href="<?= e($data['cta_url'] ?? '/gallery') ?>" class="btn btn-secondary">
                <?= e($data['cta_text']) ?>
            </a>
        </p>
        <?php endif; ?>
    </div>
</section>
