<?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;

$_s_classes = ['gallery-preview-section'];
if (!empty($data['color_scheme'])) $_s_classes[] = 'section--scheme-' . $data['color_scheme'];
if (!empty($data['section_text_color'])) $_s_classes[] = 'section--text-' . $data['section_text_color'];
if (!empty($data['text_align']))   $_s_classes[] = 'section--align-' . $data['text_align'];
$_show_img_count = !empty($data['show_image_count']);
?>
<section id="<?= e($sectionId) ?>" class="<?= e(implode(' ', $_s_classes)) ?>">
    <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>
