<?php
require_once __DIR__ . "/includes/config.php";
$page_title = "Gallery | " . $SITE_NAME;

$gallery_dir_fs  = __DIR__ . "/assets/images/gallery";
$gallery_dir_url = "/assets/images/gallery";

$gallery_items = [];
$images = []; // kept so the current gallery-content.php keeps working until it's updated

if (is_dir($gallery_dir_fs)) {
    $thumbs = glob($gallery_dir_fs . "/*-thumb.webp");
    usort($thumbs, "strnatcasecmp");

    foreach ($thumbs as $thumb_path) {
        $thumb_file = basename($thumb_path);
        $stem = substr($thumb_file, 0, -strlen("-thumb.webp"));
        $full_file = $stem . "-full.webp";
        $full_path = $gallery_dir_fs . "/" . $full_file;
        if (!is_file($full_path)) continue;

        $t = getimagesize($thumb_path);
        $f = getimagesize($full_path);
        if (!$t || !$f) continue;

        $gallery_items[] = [
            "thumb_url" => $gallery_dir_url . "/" . $thumb_file,
            "full_url"  => $gallery_dir_url . "/" . $full_file,
            "thumb_w"   => $t[0], "thumb_h" => $t[1],
            "full_w"    => $f[0], "full_h"  => $f[1],
            "alt"       => ucwords(str_replace("-", " ", $stem)),
        ];
        $images[] = $full_file;
    }
}
?>

<?php include __DIR__ . "/includes/head.php"; ?>
<?php include __DIR__ . "/includes/nav.php"; ?>
<?php include __DIR__ . "/includes/pages/gallery-content.php"; ?>
<?php include __DIR__ . "/includes/footer.php"; ?>
<?php include __DIR__ . "/includes/scripts.php"; ?>