/** * Quick lead capture list — persisted in localStorage. * Used by the Quick Lead form and dashboard widget. */ import { useLocalStorageRef } from '~/utils/useLocalStorageRef' export interface QuickLead { id: string name: string phone: string email: string product: string source: string priority: 'normal' | 'high' | 'urgent' note: string agent: string createdAt: string } const KEY = 'policy-ui-quick-leads-v1' export function useQuickLeads() { const leads = useLocalStorageRef(KEY, () => []) function addLead(entry: Omit) { const lead: QuickLead = { id: crypto.randomUUID?.() ?? String(Date.now()), createdAt: new Date().toISOString(), ...entry, } leads.value = [lead, ...leads.value] return lead } function removeLead(id: string) { leads.value = leads.value.filter((l) => l.id !== id) } /** Leads from the last N days */ function recentLeads(days: number) { const cutoff = Date.now() - days * 86_400_000 return leads.value.filter((l) => new Date(l.createdAt).getTime() >= cutoff) } return { leads, addLead, removeLead, recentLeads } }