<?php
/**
 * Accueil : intro éditoriale + tuiles des galeries publiées.
 * @var string $introHtml
 * @var list<array<string,mixed>> $galleries
 */

use App\Core\Settings;
?>
<?php if ($introHtml !== ''): ?>
    <div class="home-intro"><?= $introHtml ?></div>
<?php endif; ?>

<?php if (!empty($galleries)): ?>
    <h2 class="section-title"><?= e(Settings::get('galleries_label', 'Galeries')) ?></h2>
    <div class="folder-grid">
        <?php foreach ($galleries as $g): ?>
            <?php
            $cover = (!empty($g['cover_filename']) && !empty($g['cover_gallery_id']))
                ? media_url((int) $g['cover_gallery_id'], (string) $g['cover_filename'], 'cover')
                : null;
            ?>
            <a class="folder-item" href="<?= e(base_url($g['slug'])) ?>">
                <?php if ($cover): ?>
                    <img class="folder-cover" src="<?= e($cover) ?>" alt="<?= e($g['title']) ?>" loading="lazy">
                <?php else: ?>
                    <span class="folder-cover folder-cover--empty"></span>
                <?php endif; ?>
                <span class="folder-label"><?= e($g['title']) ?></span>
            </a>
        <?php endforeach; ?>
    </div>
<?php else: ?>
    <p class="empty">Aucune galerie publiée pour le moment.</p>
<?php endif; ?>
