import{r as c,s as h,t as j,j as e}from"./index-CEqTxpJr.js";function v(){const[a,r]=c.useState([]),[x,d]=c.useState(!0);c.useEffect(()=>{(async()=>{const{data:t,error:s}=await h.from("leads").select("*").order("created_at",{ascending:!1});s?j.error(s.message):r(t),d(!1)})()},[]);function i(){const t=["created_at","full_name","phone","email","budget","property_interest","preferred_location","source_page","message"],s=[t.join(",")].concat(a.map(p=>t.map(m=>`"${String(p[m]??"").replace(/"/g,'""')}"`).join(","))).join(`
`),o=new Blob([s],{type:"text/csv"}),l=URL.createObjectURL(o),n=document.createElement("a");n.href=l,n.download=`bridgefield-leads-${new Date().toISOString().slice(0,10)}.csv`,n.click(),URL.revokeObjectURL(l)}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"font-display text-3xl font-bold",children:"Leads"}),e.jsx("button",{onClick:i,className:"bg-navy px-4 py-2 text-[10px] font-bold uppercase tracking-widest text-ivory hover:bg-gold hover:text-navy",children:"Export CSV"})]}),e.jsx("div",{className:"mt-8 overflow-x-auto bg-white ring-1 ring-navy/10",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-navy/5 text-left text-[10px] uppercase tracking-widest text-navy/60",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"Date"}),e.jsx("th",{className:"px-4 py-3",children:"Name"}),e.jsx("th",{className:"px-4 py-3",children:"Contact"}),e.jsx("th",{className:"px-4 py-3",children:"Interest"}),e.jsx("th",{className:"px-4 py-3",children:"Source"}),e.jsx("th",{className:"px-4 py-3",children:"Message"})]})}),e.jsx("tbody",{children:x?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"p-8 text-center text-navy/40",children:"Loading…"})}):a.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"p-8 text-center text-navy/40",children:"No leads yet."})}):a.map(t=>e.jsxs("tr",{className:"border-t border-navy/5 align-top",children:[e.jsx("td",{className:"px-4 py-3 text-xs text-navy/60",children:new Date(t.created_at).toLocaleString()}),e.jsx("td",{className:"px-4 py-3 font-medium",children:t.full_name}),e.jsxs("td",{className:"px-4 py-3 text-xs",children:[e.jsx("div",{children:t.phone}),e.jsx("div",{className:"text-navy/60",children:t.email})]}),e.jsxs("td",{className:"px-4 py-3 text-xs",children:[e.jsx("div",{children:t.property_interest||"—"}),e.jsx("div",{className:"text-navy/60",children:t.budget||""}),e.jsx("div",{className:"text-navy/60",children:t.preferred_location||""})]}),e.jsx("td",{className:"px-4 py-3 text-xs text-navy/60",children:t.source_page||"—"}),e.jsx("td",{className:"px-4 py-3 max-w-xs text-xs text-navy/70",children:t.message||"—"})]},t.id))})]})})]})}export{v as component};
