"use client"; /** * The archive's month grid: a month heading, then that month's documents as * preview tiles, so a page is recognisable by its look before its title is * read. The timeline owns windowing and keyboard focus; this module owns how * one windowed item is laid out and how many tiles share a row. * * Two tiles side by side on a phone (one on the narrowest screens), three or * four on a desktop. The count comes from the grid's measured width, not from * viewport breakpoints, so the virtualizer's row model and the painted grid * can never disagree. */ import type { InboundDocumentDto } from "@/lib/validations/inbound-documents"; import { DocumentCard } from "./document-card"; /** Measured grid width → tiles per row. */ export function columnsForWidth(width: number): number { if (width >= 1000) return 4; if (width >= 760) return 3; if (width >= 330) return 2; return 1; } /** * Measured width → compact rows side by side in the list view. Stacked, the * list is one column; flowing, it fills the width the way the tiles do, with * wider cells because a row carries its title beside the preview. */ export function listColumnsForWidth(width: number): number { if (width >= 1100) return 3; if (width >= 700) return 2; return 1; } /** Height the flowing arrangement reserves above each row for month names. */ export const FLOW_MONTH_LABEL_PX = 24; /** Gap between tiles and between rows, in px (`gap-4` / `pb-4`). */ const GRID_GAP_PX = 16; /** * First guess at a row's height before the virtualizer measures it: a 4:3 * preview across the tile's width plus the title and meta lines under it. */ export function estimatedRowHeight( width: number, columns: number, view: "cards" | "list" = "cards", flow = false, ): number { const extra = flow ? FLOW_MONTH_LABEL_PX - GRID_GAP_PX : 0; if (view === "list") return 84 + GRID_GAP_PX + extra; const cols = Math.max(1, columns); const tileWidth = Math.max(0, (width - GRID_GAP_PX * (cols - 1)) / cols); return Math.round(tileWidth * 0.75) + 96 + GRID_GAP_PX + extra; } export function DocumentMonthHeading({ label }: { label: string }) { return (