const DRAFT_PREFIX = 'restock-draft'; export type RestockDraftData = { stockType: 'good' | 'reject'; selectedProductId: string; quantities: Record; notes: string; photo?: string; }; function getKey(type: 'create' | 'edit', userId?: number): string { if (type === 'edit') { return `${DRAFT_PREFIX}-edit-${userId ?? 'anon'}`; } return `${DRAFT_PREFIX}-create-${userId ?? 'anon'}`; } export function saveRestockDraft( type: 'create' | 'edit', data: RestockDraftData, userId?: number, ): boolean { if (type !== 'create') { return false; } try { const key = getKey(type, userId); localStorage.setItem(key, JSON.stringify(data)); return true; } catch { return false; } } export function loadRestockDraft( type: 'create' | 'edit', userId?: number, ): RestockDraftData | null { try { const key = getKey(type, userId); const raw = localStorage.getItem(key); if (!raw) { return null; } return JSON.parse(raw) as RestockDraftData; } catch { return null; } } export function clearRestockDraft( type: 'create' | 'edit', userId?: number, ): void { try { const key = getKey(type, userId); localStorage.removeItem(key); } catch { // ignore } }