import "server-only"; import type { PoolClient } from "pg"; import { getSession } from "./auth/session"; import { currentKitchenDisplay } from "./auth/kids"; import { listDishes, type DishSummary } from "./dishes"; import { currentRound } from "./rounds"; // Küchendisplay und Präsentation (26.11.28): wer darf ansehen, und was steht an. /** Wer ein Rezept präsentieren darf: eine Sitzung (nicht Gast) oder ein Küchendisplay. */ export async function presenter(): Promise<{ householdId: string; display: boolean } | null> { const session = await getSession(); if (session) return session.role === "guest" ? null : { householdId: session.householdId, display: false }; const device = await currentKitchenDisplay(); return device ? { householdId: device.householdId, display: true } : null; } export type PlannedDish = { slotId: string; dishId: string; title: string; photo: string | null; portions: number; cookName: string | null; plannedDay: string | null }; /** Die noch nicht gekochten Gerichte der laufenden Runde, in Reihenfolge; das erste ist „Heute“. */ export async function upcoming(client: PoolClient): Promise { const round = await currentRound(client); if (!round || round.status === "open") return []; const { rows } = await client.query( `select s.id as "slotId", d.id as "dishId", d.title, d.photo_path as photo, s.portions, m.display_name as "cookName", to_char(s.planned_day, 'YYYY-MM-DD') as "plannedDay" from slots s join dishes d on d.id = s.dish_id left join members m on m.id = s.cook_member_id where s.round_id = $1 and s.cooked_at is null order by s.position`, [round.id], ); return rows; } export async function kitchenOverview(client: PoolClient): Promise<{ next: PlannedDish[]; dishes: DishSummary[] }> { return { next: await upcoming(client), dishes: await listDishes(client) }; }