1import{r,j as e}from"./main-CXMzf830.js";import{l as L}from"./admin.functions-CAl_xtTX.js";import{C as S,a as N,b as y,c as E,d as T}from"./card-DO69w2hu.js";import{I as D}from"./input-B7ah-YIN.js";import{B as R}from"./button-CJKiYS16.js";import{T as B,a as U,b as x,c as n,d as k,e as t}from"./table-CQHwuP5I.js";import{D as H}from"./download-C7UqfkQk.js";import"./createServerFn-CFPAJqaE.js";import"./utils-BX5MYgLu.js";function V(){const[c,p]=r.useState([]),[u,f]=r.useState(!0),[l,g]=r.useState(null),[i,b]=r.useState("");r.useEffect(()=>{L().then(s=>p(s.leads)).catch(s=>g(s instanceof Error?s.message:"Failed")).finally(()=>f(!1))},[]);const o=r.useMemo(()=>{if(!i.trim())return c;const s=i.toLowerCase();return c.filter(a=>[a.first_name,a.last_name,a.email,a.company,a.lead_magnet,a.utm_source].filter(Boolean).some(d=>String(d).toLowerCase().includes(s)))},[c,i]),w=()=>{const s=["created_at","first_name","last_name","email","company","job_title","phone","lead_magnet","source_page","utm_source","utm_medium","utm_campaign"],a=o.map(C=>s.map(v=>{const j=C[v];return j==null?"":`"${String(j).replace(/"/g,'""')}"`}).join(",")),d=[s.join(","),...a].join(` 2`),_=new Blob([d],{type:"text/csv"}),h=URL.createObjectURL(_),m=document.createElement("a");m.href=h,m.download=`leads-${new Date().toISOString().slice(0,10)}.csv`,m.click(),URL.revokeObjectURL(h)};return e.jsxs(S,{children:[e.jsxs(N,{className:"flex flex-row items-center justify-between gap-4 space-y-0",children:[e.jsxs("div",{children:[e.jsx(y,{children:"Lead submissions"}),e.jsxs(E,{children:[o.length," of ",c.length," shown"]})]}),e.jsxs(R,{variant:"outline",size:"sm",onClick:w,disabled:!o.length,children:[e.jsx(H,{className:"mr-2 h-4 w-4"})," Export CSV"]})]}),e.jsxs(T,{children:[e.jsx(D,{placeholder:"Search name, email, company, sourceâ¦",value:i,onChange:s=>b(s.target.value),className:"mb-4 max-w-md"}),u&&e.jsx("p",{className:"text-muted-foreground",children:"Loadingâ¦"}),l&&e.jsx("p",{className:"text-destructive",children:l}),!u&&!l&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(B,{children:[e.jsx(U,{children:e.jsxs(x,{children:[e.jsx(n,{children:"Date"}),e.jsx(n,{children:"Name"}),e.jsx(n,{children:"Email"}),e.jsx(n,{children:"Company"}),e.jsx(n,{children:"Magnet"}),e.jsx(n,{children:"Source"})]})}),e.jsxs(k,{children:[o.map(s=>e.jsxs(x,{children:[e.jsx(t,{className:"whitespace-nowrap text-xs text-muted-foreground",children:new Date(s.created_at).toLocaleDateString()}),e.jsxs(t,{children:[s.first_name," ",s.last_name]}),e.jsx(t,{children:e.jsx("a",{className:"hover:underline",href:`mailto:${s.email}`,children:s.email})}),e.jsx(t,{children:s.company||"â"}),e.jsx(t,{className:"max-w-[200px] truncate",children:s.lead_magnet}),e.jsx(t,{children:s.utm_source||"direct"})]},s.id)),o.length===0&&e.jsx(x,{children:e.jsx(t,{colSpan:6,className:"text-center text-muted-foreground",children:"No leads found."})})]})]})})]})]})}export{V as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.