import { useState } from 'react' import { X, Plus, Trash2, FileText, Clock, Layers, ChevronRight } from 'lucide-react' import type { Page } from '../App' function formatDate(ts: number) { const d = new Date(ts) const now = Date.now() const diff = now - ts if (diff < 60_000) return 'Just now' if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m ago` if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)}h ago` return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: d.getFullYear() !== new Date().getFullYear() ? 'numeric' : undefined }) } function countBlocksDeep(blocks: Page['blocks']): number { let n = 0 for (const b of blocks) { n++ if (b.slots) for (const slot of b.slots) n += countBlocksDeep(slot) } return n } export function PagesModal({ pages, currentPageId, onLoad, onNew, onDelete, onClose, }: { pages: Page[] currentPageId: string | null onLoad: (page: Page) => void onNew: () => void onDelete: (id: string) => Promise onClose: () => void }) { const [confirmDelete, setConfirmDelete] = useState(null) return (
e.stopPropagation()} > {/* Header */}

Pages

{pages.length} saved page{pages.length !== 1 ? 's' : ''}

{/* Page list */}
{pages.length === 0 ? (

No saved pages yet

Save your current canvas to get started

) : (
{pages.map(page => { const isCurrent = page.id === currentPageId const blockCount = countBlocksDeep(page.blocks) const isDeleting = confirmDelete === page.id return (
{ if (!isDeleting) { onLoad(page); onClose() } }} > {/* Theme swatch */}
{[page.theme.background, page.theme.primary, page.theme.muted, page.theme.accent].map((c, i) => (
))}
{/* Info */}
{page.name} {isCurrent && ( OPEN )}
{blockCount} block{blockCount !== 1 ? 's' : ''} Updated {formatDate(page.updatedAt)}
{/* Actions */}
e.stopPropagation()}> {isDeleting ? ( <> Delete? ) : ( <> )}
) })}
)}
) }