(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,24230,e=>{"use strict";var t=e.i(43476),s=e.i(71645);function a(){let[e,a]=(0,s.useState)([]),[l,n]=(0,s.useState)(0),[d,i]=(0,s.useState)(""),[c,r]=(0,s.useState)(1),[o,x]=(0,s.useState)(!0),[h,p]=(0,s.useState)(new Set);function m(){x(!0);let e=new URLSearchParams({page:String(c)});d&&e.set("status",d),fetch(`/api/admin/leads?${e}`).then(e=>e.json()).then(e=>{a(e.leads),n(e.total),p(new Set)}).catch(console.error).finally(()=>x(!1))}async function u(e){0!==h.size&&(await fetch("/api/admin/leads",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({leadIds:Array.from(h),status:e})}),m())}return(0,s.useEffect)(()=>{m()},[c,d]),(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-bold",children:"All Leads"}),(0,t.jsxs)("p",{className:"text-sm text-white/50",children:[l," total leads"]})]}),(0,t.jsx)("button",{onClick:function(){let e=new URLSearchParams({format:"csv"});d&&e.set("status",d),window.open(`/api/admin/leads?${e}`,"_blank")},className:"rounded-xl border border-white/10 px-4 py-2 text-sm font-semibold text-white/70 transition hover:bg-white/10",children:"Export CSV"})]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,t.jsxs)("select",{value:d,onChange:e=>{i(e.target.value),r(1)},className:"rounded-xl border border-white/10 bg-white/5 px-4 py-2 text-sm text-white",children:[(0,t.jsx)("option",{value:"",children:"All statuses"}),(0,t.jsx)("option",{value:"new",children:"New"}),(0,t.jsx)("option",{value:"contacted",children:"Contacted"}),(0,t.jsx)("option",{value:"converted",children:"Converted"})]}),h.size>0&&(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsxs)("button",{onClick:()=>u("contacted"),className:"rounded-xl bg-blue-500/20 px-3 py-2 text-xs text-blue-400",children:["Mark Contacted (",h.size,")"]}),(0,t.jsxs)("button",{onClick:()=>u("converted"),className:"rounded-xl bg-green-500/20 px-3 py-2 text-xs text-green-400",children:["Mark Converted (",h.size,")"]})]})]}),o?(0,t.jsx)("div",{className:"py-12 text-center text-white/30",children:"Loading..."}):(0,t.jsx)("div",{className:"overflow-x-auto rounded-2xl border border-white/10",children:(0,t.jsxs)("table",{className:"min-w-full text-sm",children:[(0,t.jsx)("thead",{className:"border-b border-white/10 bg-white/5 text-left text-white/50",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"px-4 py-3 w-8",children:(0,t.jsx)("input",{type:"checkbox",onChange:t=>p(t.target.checked?new Set(e.map(e=>e._id)):new Set),className:"rounded"})}),(0,t.jsx)("th",{className:"px-4 py-3 font-semibold",children:"Name"}),(0,t.jsx)("th",{className:"px-4 py-3 font-semibold",children:"Email"}),(0,t.jsx)("th",{className:"px-4 py-3 font-semibold",children:"Phone"}),(0,t.jsx)("th",{className:"px-4 py-3 font-semibold",children:"Bot"}),(0,t.jsx)("th",{className:"px-4 py-3 font-semibold",children:"Status"}),(0,t.jsx)("th",{className:"px-4 py-3 font-semibold",children:"Date"})]})}),(0,t.jsx)("tbody",{className:"divide-y divide-white/5",children:e.map(e=>(0,t.jsxs)("tr",{className:"hover:bg-white/5",children:[(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsx)("input",{type:"checkbox",checked:h.has(e._id),onChange:()=>{var t;return t=e._id,void p(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},className:"rounded"})}),(0,t.jsx)("td",{className:"px-4 py-3 font-medium",children:e.name||"—"}),(0,t.jsx)("td",{className:"px-4 py-3 text-[var(--color-accent-green-light)]",children:e.email||"—"}),(0,t.jsx)("td",{className:"px-4 py-3 text-white/50",children:e.phone||"—"}),(0,t.jsx)("td",{className:"px-4 py-3 text-xs text-white/40",children:e.botId?.name||"—"}),(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsx)("span",{className:`rounded-full px-2 py-0.5 text-xs font-semibold ${"new"===e.status?"bg-yellow-500/20 text-yellow-400":"contacted"===e.status?"bg-blue-500/20 text-blue-400":"bg-green-500/20 text-green-400"}`,children:e.status})}),(0,t.jsx)("td",{className:"px-4 py-3 text-xs text-white/40",children:new Date(e.createdAt).toLocaleDateString()})]},e._id))})]})}),l>20&&(0,t.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,t.jsx)("button",{onClick:()=>r(e=>Math.max(1,e-1)),disabled:1===c,className:"rounded-xl border border-white/10 px-4 py-2 text-sm disabled:opacity-30",children:"Previous"}),(0,t.jsxs)("span",{className:"text-sm text-white/50",children:["Page ",c]}),(0,t.jsx)("button",{onClick:()=>r(e=>e+1),disabled:c>=Math.ceil(l/20),className:"rounded-xl border border-white/10 px-4 py-2 text-sm disabled:opacity-30",children:"Next"})]})]})}e.s(["default",()=>a])}]);