const DRAFT_KEY_PREFIX = 'recall_draft_' const DRAFT_TTL = 7 * 24 * 60 * 60 * 1000 // 7 days interface Draft { title: string content: string type: string tags: string[] savedAt: number } export function saveDraft(noteId: string, data: Draft): void { if (typeof window === 'undefined') return localStorage.setItem(DRAFT_KEY_PREFIX + noteId, JSON.stringify({ ...data, savedAt: Date.now() })) } export function loadDraft(noteId: string): Draft | null { if (typeof window === 'undefined') return null const stored = localStorage.getItem(DRAFT_KEY_PREFIX + noteId) if (!stored) return null try { const draft = JSON.parse(stored) as Draft if (Date.now() - draft.savedAt > DRAFT_TTL) { deleteDraft(noteId) return null } return draft } catch { return null } } export function deleteDraft(noteId: string): void { if (typeof window === 'undefined') return localStorage.removeItem(DRAFT_KEY_PREFIX + noteId) }