/** The two pages: the entrance (catalogue and intake form) and a case. */ import { escape } from "./html.ts"; import { catalogueNumber, conditionOf, vitrineOf, VITRINES } from "./museum.ts"; import type { Item, ItemWithCount, Note } from "./db.ts"; function layout(env: string, commit: string, body: string): string { return ` lost-property ${body}

lost-property ${escape(env)} ${commit ? "@ " + escape(commit) : ""}

`; } export function renderHome(items: ItemWithCount[], env: string, commit: string): string { const rows = items .map((item) => { const vitrine = vitrineOf(item.description); const short = item.description.length > 80 ? item.description.slice(0, 80) + "…" : item.description; return `
  • ${escape(short)}
    ${escape(catalogueNumber(item.id, item.created_at))}${escape(VITRINES[vitrine]!)}
    ${item.note_count} note${item.note_count === 1 ? "" : "s"} · accessioned ${escape(item.created_at)}
  • `; }) .join(""); return layout( env, commit, `

    lost-property

    A museum of lost things. Describe what you lost; the museum accessions it — a catalogue number, a vitrine, a plaque written in the flat voice of a museum label. Other visitors can leave a note on any case: that they saw one like it, or that they have the other half.

    `, ); } export function renderCase(item: Item, notes: Note[], env: string, commit: string): string { const vitrineIndex = vitrineOf(item.description); const noteRows = notes .map( (n) => `
    ${n.kind === "match" ? "Has the other half" : "Saw one like it"}

    ${escape(n.body)}

    ${escape(n.created_at)}
    `, ) .join(""); return layout( env, commit, `

    ← lost-property

    ${escape(catalogueNumber(item.id, item.created_at))} · Vitrine ${vitrineIndex + 1}

    ${escape(VITRINES[vitrineIndex]!)}

    ${escape(item.description)}

    Accessioned
    ${escape(item.created_at)}
    Condition
    ${escape(conditionOf(item.id))}

    Notes

    ${noteRows || `

    No notes yet.

    `}
    `, ); }