// Pure helpers shared by server and client components. Must not be "use client", // or server pages calling these get a client reference instead of the function. export type WaitlistLine = { eventOptionId: string; variantId?: string | null; label: string }; /** The sold-out lines of an event, for the waitlist button. */ export function soldOutLines(options: { id: string; name: string; stockLimit?: number; availableCount?: number | null; variants?: { id: string; name: string; stockLimit?: number; availableCount?: number | null }[] | null }[]): WaitlistLine[] { const out: WaitlistLine[] = []; for (const o of options || []) { const optOut = (o.stockLimit ?? 0) > 0 && o.availableCount !== undefined && o.availableCount !== null && o.availableCount <= 0; const variants = o.variants || []; if (variants.length > 0) { for (const v of variants) { const vOut = (v.stockLimit ?? 0) > 0 && v.availableCount !== undefined && v.availableCount !== null && v.availableCount <= 0; if (optOut || vOut) out.push({ eventOptionId: o.id, variantId: v.id, label: `${o.name} (${v.name})` }); } } else if (optOut) { out.push({ eventOptionId: o.id, label: o.name }); } } return out; }