1import{r as m,t as h,J as u,j as e,B as n,b as i,c as r,G as p,d as w,s as y,e as C}from"./index-U8D282DB.js";import{I as v}from"./input-DFtjl8GZ.js";import{B as S}from"./badge-BmpMbrZ9.js";import{R as A}from"./refresh-cw-ChEPvTuC.js";import{S as L}from"./search-C5_ObWCH.js";import{B as _}from"./ban-DRDf7nyd.js";import"./useComposition-DGvQVl2f.js";const F={pending_payment:"bg-yellow-500/10 text-yellow-500 border-yellow-500/20",active:"bg-green-500/10 text-green-500 border-green-500/20",partially_used:"bg-blue-500/10 text-blue-500 border-blue-500/20",fully_used:"bg-gray-500/10 text-gray-400 border-gray-500/20",expired:"bg-red-500/10 text-red-500 border-red-500/20",cancelled:"bg-red-500/10 text-red-500 border-red-500/20"};function z(){const[t,f]=m.useState(""),[l,g]=m.useState("all"),{data:a=[],isLoading:j,refetch:d}=h.giftVouchers.adminList.useQuery(),o=h.giftVouchers.adminCancel.useMutation({onSuccess:()=>{u.success("Voucher cancelled"),d()},onError:s=>u.error(s.message)}),x=a.filter(s=>{const c=!t||s.code?.toLowerCase().includes(t.toLowerCase())||s.recipientName?.toLowerCase().includes(t.toLowerCase())||s.recipientEmail?.toLowerCase().includes(t.toLowerCase())||s.purchaserName?.toLowerCase().includes(t.toLowerCase()),b=l==="all"||s.status===l;return c&&b}),V=a.reduce((s,c)=>s+parseFloat(c.amount||"0"),0),G=a.filter(s=>s.status==="active"||s.status==="partially_used").length,N=a.filter(s=>s.status==="active"||s.status==="partially_used").reduce((s,c)=>s+parseFloat(c.remainingAmount||"0"),0);return e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:48",className:"space-y-6",children:[e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:49",className:"flex items-center justify-between",children:[e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:50",children:[e.jsx("h1",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:51",className:"text-2xl font-bold",children:"Gift Vouchers"}),e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:52",className:"text-sm text-muted-foreground",children:"Manage all gift vouchers purchased by customers"})]}),e.jsxs(n,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:54",variant:"outline",size:"sm",onClick:()=>d(),children:[e.jsx(A,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:55",className:"h-4 w-4 mr-2"}),"Refresh"]})]}),e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:61",className:"grid grid-cols-1 sm:grid-cols-4 gap-4",children:[e.jsx(i,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:62",children:e.jsxs(r,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:63",className:"p-4 flex items-center gap-3",children:[e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:64",className:"h-10 w-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(p,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:65",className:"h-5 w-5 text-primary"})}),e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:67",children:[e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:68",className:"text-xs text-muted-foreground",children:"Total Vouchers"}),e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:69",className:"text-xl font-bold",children:a.length})]})]})}),e.jsx(i,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:73",children:e.jsxs(r,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:74",className:"p-4 flex items-center gap-3",children:[e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:75",className:"h-10 w-10 rounded-lg bg-green-500/10 flex items-center justify-center",children:e.jsx(w,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:76",className:"h-5 w-5 text-green-500"})}),e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:78",children:[e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:79",className:"text-xs text-muted-foreground",children:"Active"}),e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:80",className:"text-xl font-bold",children:G})]})]})}),e.jsx(i,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:84",children:e.jsxs(r,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:85",className:"p-4 flex items-center gap-3",children:[e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:86",className:"h-10 w-10 rounded-lg bg-blue-500/10 flex items-center justify-center",children:e.jsx(y,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:87",className:"h-5 w-5 text-blue-500"})}),e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:89",children:[e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:90",className:"text-xs text-muted-foreground",children:"Total Sold"}),e.jsxs("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:91",className:"text-xl font-bold",children:["$",V.toFixed(0)]})]})]})}),e.jsx(i,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:95",children:e.jsxs(r,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:96",className:"p-4 flex items-center gap-3",children:[e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:97",className:"h-10 w-10 rounded-lg bg-amber-500/10 flex items-center justify-center",children:e.jsx(C,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:98",className:"h-5 w-5 text-amber-500"})}),e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:100",children:[e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:101",className:"text-xs text-muted-foreground",children:"Outstanding"}),e.jsxs("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:102",className:"text-xl font-bold",children:["$",N.toFixed(0)]})]})]})})]}),e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:109",className:"flex flex-wrap gap-3",children:[e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:110",className:"relative flex-1 min-w-[200px]",children:[e.jsx(L,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:111",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(v,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:112",placeholder:"Search by code, name, or email...",value:t,onChange:s=>
1f(s.target.value),className:"pl-9"})]}),e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:119",className:"flex gap-1",children:["all","active","partially_used","pending_payment","fully_used","expired","cancelled"].map(s=>e.jsx(n,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:121",variant:l===s?"default":"outline",size:"sm",onClick:()=>g(s),className:"text-xs capitalize",children:s==="all"?"All":s.replace(/_/g," ")},s))})]}),j?e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:136",className:"text-center py-12 text-muted-foreground",children:"Loading vouchers..."}):x.length===0?e.jsxs("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:138",className:"text-center py-12",children:[e.jsx(p,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:139",className:"h-10 w-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:140",className:"text-muted-foreground",children:"No vouchers found"})]}):e.jsx(i,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:143",children:e.jsx(r,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:144",className:"p-0",children:e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:145",className:"overflow-x-auto",children:e.jsxs("table",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:146",className:"w-full text-sm",children:[e.jsx("thead",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:147",children:e.jsxs("tr",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:148",className:"border-b bg-muted/50",children:[e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:149",className:"text-left p-3 font-medium",children:"Code"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:150",className:"text-left p-3 font-medium",children:"Recipient"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:151",className:"text-left p-3 font-medium",children:"Purchaser"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:152",className:"text-right p-3 font-medium",children:"Amount"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:153",className:"text-right p-3 font-medium",children:"Remaining"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:154",className:"text-left p-3 font-medium",children:"Status"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:155",className:"text-left p-3 font-medium",children:"Created"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:156",className:"text-left p-3 font-medium",children:"Expires"}),e.jsx("th",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:157",className:"text-right p-3 font-medium",children:"Actions"})]})}),e.jsx("tbody",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:160",children:x.map(s=>e.jsxs("tr",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:162",className:"border-b hover:bg-muted/30 transition-colors",children:[e.jsx("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:163",className:"p-3 font-mono font-semibold text-xs",children:s.code}),e.jsxs("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:164",className:"p-3",children:[e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:165",className:"font-medium",children:s.recipientName}),e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:166",className:"text-xs text-muted-foreground",children:s.recipientEmail})]}),e.jsx("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:168",className:"p-3",children:e.jsx("div",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:169",className:"font-medium",children:s.purchaserName||"â"})}),e.jsxs("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:171",className:"p-3 text-right font-semibold",children:["$",parseFloat(s.amount).toFixed(2)]}),e.jsxs("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:172",className:"p-3 text-right font-semibold",children:["$",parseFloat(s.remainingAmount).toFixed(2)]}),e.jsx("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:175",className:"p-3",children:e.jsx(S,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:176",variant:"outline",className:F[s.status]||"",children:s.status?.replace(/_/g," ")})}),e.jsx("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:180",className:"p-3 text-xs text-muted-foreground",children:s.createdAt?new Date(s.createdAt).toLocaleDateString("en-AU"):"â"}),e.jsx("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:183",className:"p-3 text-xs text-muted-foreground",children:s.expiresAt?new Date(s.expiresAt).toLocaleDateString("en-AU"):"â"}),e.jsx("td",{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:186",className:"p-3 text-right",children:(s.status==="active"||s.status==="partially_used")&&e.jsxs(n,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:188",variant:"outline",size:"sm",className:"text-red-500 border-red-500/30 hover:bg-red-500/10 h-7 text-xs",onClick:()=>{confirm(`Cancel voucher ${s.code}? This cannot be undone.`)&&o.mutate({id:s.id})},disabled:o.isPending,children:[e.jsx(_,{"data-loc":"client/src/pages/admin/GiftVouchers.tsx:199",className:"h-3 w-3 mr-1"}),"Cancel"]})})]},s.id))})]})})})})]})}export{z 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.