// A guest's name/contact, remembered locally so checkout doesn't ask again // on their next order from this browser. const STORAGE_KEY = 'ghost-kitchen-guest-identity' export type GuestIdentity = { name: string; contact: string } const isGuestIdentity = (value: unknown): value is GuestIdentity => typeof value === 'object' && value !== null && typeof (value as GuestIdentity).name === 'string' && typeof (value as GuestIdentity).contact === 'string' export const getGuestIdentity = (): GuestIdentity | null => { try { const raw = window.localStorage.getItem(STORAGE_KEY) if (!raw) return null const parsed: unknown = JSON.parse(raw) return isGuestIdentity(parsed) ? parsed : null } catch { return null } } export const saveGuestIdentity = (identity: GuestIdentity) => { try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(identity)) } catch { // Unavailable (private mode, quota) — checkout still works, it just // asks again next time. } } export const clearGuestIdentity = () => { try { window.localStorage.removeItem(STORAGE_KEY) } catch { // Unavailable — nothing to clear. } }