import Link from 'next/link'; import Image from 'next/image'; import { imageUrl } from '@/lib/urls'; import { SubpageSectionConfig } from '@/lib/config'; interface SubpageAlbum { id: string; slug: string; albumName: string; assetCount: number; albumThumbnailAssetId: string | null; } interface Placeholder { blurDataURL?: string; dominantColor?: string; } interface SubpageGridViewProps { slug: string; title?: string; subtitle?: string; albums: SubpageAlbum[]; coverPlaceholders: (Placeholder | null)[]; sections?: SubpageSectionConfig[]; /** 1-based position among all subpages — feeds the "03 — Collection" kicker. */ index?: number; } const pad2 = (n: number) => String(n).padStart(2, '0'); const photoCount = (n: number) => `${n} ${n === 1 ? 'photo' : 'photos'}`; function AlbumGrid({ albums, placeholderMap, slug, }: { albums: SubpageAlbum[]; placeholderMap: Map; slug: string; }) { return (
{albums.map((album, i) => { const ph = placeholderMap.get(album.id) ?? null; return ( {album.albumThumbnailAssetId ? ( ) : ( {/* Always-visible caption bar — shown by presets that use it. */} ); })}
); } export function SubpageGridView({ slug, title, subtitle, albums, coverPlaceholders, sections, index, }: SubpageGridViewProps) { // Build lookup maps once const albumMap = new Map(albums.map((a) => [a.id, a])); const placeholderMap = new Map(albums.map((a, i) => [a.id, coverPlaceholders[i] ?? null])); const hasSections = sections && sections.length > 0; const totalPhotos = albums.reduce((sum, a) => sum + a.assetCount, 0); return (
{(title || subtitle) && (
{index !== undefined && ( )} {title &&

{title}

} {subtitle &&

{subtitle}

}
)} {/* Typographic Table of Contents */} {hasSections && ( )} {/* Sectioned layout */} {hasSections ? ( sections.map((sec) => { const sectionAlbums = sec.albumIds .map((id) => albumMap.get(id)) .filter(Boolean) as SubpageAlbum[]; return (

{sec.title}

{sec.description &&

{sec.description}

}
); }) ) : ( /* Flat layout (no sections) */ )}
); }