import { packageStorage } from 'kody:runtime' import { formatEventWhen, HOME_REDIRECT_KEY, pieLook, slugify } from './pies.ts' import { getEvent, listPies } from './store.ts' /** * Read one pie night: event details and every pie on the list. * * @param params.code The event code (forgiving about capitals and spaces). Defaults to the home page event, if one is set. * @returns `{ event, pies }` where each pie has `who`, `pie`, `note`, and a `look` (emoji + color), or `{ event: null, pies: [] }`. * * @example * import pieNight from 'kody:@owner/pie-night' * const { event, pies } = await pieNight({ code: 'smith-pie-night-2026' }) */ export default async function pieNight(params: { code?: string } = {}) { const fallback = await packageStorage().get(HOME_REDIRECT_KEY) const slug = slugify(params.code || (typeof fallback === 'string' ? fallback : '')) const event = slug ? await getEvent(slug) : null if (!event) return { event: null, pies: [] } const pies = await listPies(event.night) return { event: { slug: event.slug, code: event.code, title: event.title, date: event.date, time: event.time, place: event.place, blurb: event.blurb, theme: event.theme, when: formatEventWhen(event) }, pies: pies.map((p) => ({ who: p.who, pie: p.pie, note: p.note, createdAt: new Date(p.createdAt).toISOString(), look: pieLook(p.pie) })), } }