1import{e as P,u as Q,f as R,j as e}from"./data-vendor-vk1v0Quf.js";import{r as d}from"./react-vendor-BKvR7kP7.js";import{j as U,B as j,S as F,I as z,o as A,p as H,q as I,r as O,s as C,aa as V,Y as q}from"./index-DhiJfMte.js";import{A as $}from"./AdminLayout-DhjeY7NK.js";import{B as K}from"./badge-ClzW_0OU.js";import{C as f,c as g}from"./card-S91eXzYI.js";import{T as Y,a as G,b as m,c,d as J,e as n}from"./table-D4PO6WDq.js";import{D as W}from"./download-jU6CR9UK.js";import{P as X}from"./package-Bp8AKodw.js";import{U as Z}from"./users-CZ3o6lXn.js";import{C as ee}from"./circle-check-q6t7nvLQ.js";import{C as se}from"./chevron-right-Dj03duT7.js";import{f as y}from"./format-cwXK75ha.js";import"./skeleton-CwRWBrAT.js";import"./avatar-CII0ItLT.js";import"./calendar-DLGTLifL.js";import"./chart-column-BxbmYcyy.js";const M=["new","contacted","closed"];function ye(){const[o,u]=d.useState(""),[x,T]=d.useState("all"),[L,E]=d.useState(new Set),{toast:w}=U(),k=P(),{data:v=[],isLoading:B}=Q({queryKey:["admin-shuttle-enquiries"],queryFn:async()=>{const{data:s,error:a}=await q.from("shuttle_enquiries").select("*").order("created_at",{ascending:!1});if(a)throw a;return s}}),S=R({mutationFn:async({id:s,status:a})=>{const{error:t}=await q.from("shuttle_enquiries").update({status:a}).eq("id",s);if(t)throw t},onSuccess:()=>{k.invalidateQueries({queryKey:["admin-shuttle-enquiries"]}),w({title:"Status updated"})},onError:()=>{w({title:"Failed to update status",variant:"destructive"})}}),i=d.useMemo(()=>v.filter(s=>{const a=x==="all"||s.status===x,t=o.trim().toLowerCase(),r=!t||s.name.toLowerCase().includes(t)||s.phone.toLowerCase().includes(t)||s.email.toLowerCase().includes(t);return a&&r}),[v,x,o]),h=d.useMemo(()=>{const s=i.length,a=i.filter(r=>r.status==="new").length,t=i.filter(r=>r.status==="closed").length;return{total:s,fresh:a,closed:t}},[i]),D=()=>{const s=["Date","Name","Phone","Email","Buyer Type","Product","Quantity","Message","Status"],a=i.map(l=>[y(new Date(l.created_at),"yyyy-MM-dd HH:mm"),l.name,l.phone,l.email,l.buyer_type,l.product_interest,l.quantity||"",l.message||"",l.status]),t=[s,...a].map(l=>l.map(_=>`"${String(_).replace(/"/g,'""')}"`).join(",")).join(` 2`),r=new Blob([t],{type:"text/csv"}),b=URL.createObjectURL(r),p=document.createElement("a");p.href=b,p.download=`shuttle-enquiries-${y(new Date,"yyyy-MM-dd")}.csv`,p.click(),URL.revokeObjectURL(b)};return e.jsx($,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Shuttle Enquiries"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Bulk pricing requests from the Shuttles page"})]}),e.jsxs(j,{variant:"outline",onClick:D,disabled:!i.length,children:[e.jsx(W,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(f,{children:e.jsxs(g,{className:"flex items-center gap-3 p-4",children:[e.jsx(X,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:h.total}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total enquiries"})]})]})}),e.jsx(f,{children:e.jsxs(g,{className:"flex items-center gap-3 p-4",children:[e.jsx(Z,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:h.fresh}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"New / unattended"})]})]})}),e.jsx(f,{children:e.jsxs(g,{className:"flex items-center gap-3 p-4",children:[e.jsx(ee,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:h.closed}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Closed"})]})]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(F,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(z,{placeholder:"Search name, phone or email...",className:"pl-9",value:o,onChange:s=>u(s.target.value)})]}),e.jsxs(A,{value:x,onValueChange:T,children:[e.jsx(H,{className:"w-[180px]",children:e.jsx(I,{placeholder:"Status"})}),e.jsxs(O,{className:"bg-background z-50",children:[e.jsx(C,{value:"all",children:"All statuses"}),M.map(s=>e.jsx(C,{value:s,children:s},s))]})]})]}),e.jsx("div",{className:"rounded-lg border",children:e.jsxs(Y,{children:[e.jsx(G,{children:e.jsxs(m,{children:[e.jsx(c,{className:"w-8"}),e.jsx(c,{children:"Name"}),e.jsx(c,{children:"Buyer Type"}),e.jsx(c,{children:"Product"}),e.jsx(c,{children:"Phone"}),e.jsx(c,{children:"Status"}),e.jsx(c,{children:"Date"})]})}),e.jsx(J,{children:B?e.jsx(m,{children:e.jsx(n,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"Loading..."})}):i.length===0?e.jsx(m,{children:e.jsx(n,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No enquiries found."})}):i.map(s=>{const a=L.has(s.id);return e.jsxs(d.Fragment,{children:[e.jsxs(m,{children:[e.jsx(n,{children:e.jsx(j,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>E(t=>{const r=new Set(t);return r.has(s.id)?r.delete(s.id):r.add(s.id),r}),children:a?e.jsx(V,{className:"h-4 w-4"}):e.jsx(se,{className:"h-4 w-4"})})}),e.jsx(n,{className:"font-medium",children:s.name}
2),e.jsx(n,{className:"capitalize",children:s.buyer_type}),e.jsx(n,{children:s.product_interest}),e.jsx(n,{children:s.phone}),e.jsx(n,{children:e.jsx(K,{variant:s.status==="new"?"default":"secondary",children:s.status})}),e.jsx(n,{className:"whitespace-nowrap text-sm text-muted-foreground",children:y(new Date(s.created_at),"dd MMM yyyy")})]}),a&&e.jsx(m,{children:e.jsx(n,{colSpan:7,className:"bg-muted/40",children:e.jsxs("div",{className:"grid gap-x-8 gap-y-2 p-2 sm:grid-cols-2 lg:grid-cols-3 text-sm",children:[e.jsx(N,{label:"Email",value:s.email}),e.jsx(N,{label:"Quantity",value:s.quantity}),e.jsx(N,{label:"Message",value:s.message}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 pt-2 sm:col-span-2 lg:col-span-3",children:M.map(t=>e.jsxs(j,{size:"sm",variant:s.status===t?"default":"outline",disabled:S.isPending||s.status===t,onClick:()=>S.mutate({id:s.id,status:t}),className:"capitalize",children:["Mark ",t]},t))})]})})},`${s.id}-detail`)]},s.id)})})]})})]})})}function N({label:o,value:u}){return u?e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[o,": "]}),e.jsx("span",{className:"font-medium",children:u})]}):null}export{ye as default};
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.