1import{r as t,e as p,j as e,t as h}from"./edge-BOITG1XR.js";import{L as g}from"./mod-DxqX0N6D.js";import{S as C}from"./mod-B2Tl8dXI.js";import{C as P}from"./mod-E2spV6fa.js";import{C as A}from"./mod-B33gStZf.js";import{D as L}from"./mod-ByZwUIgr.js";import{S as D}from"./mod-CKg_ZYcm.js";import{P as E}from"./mod-BC0FuShf.js";import{C as T}from"./mod-gbHpssdV.js";const O={pending:"bg-yellow-100 text-yellow-700",ready:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-red-100 text-red-700"},_=[{value:"all",label:"All"},{value:"pending",label:"Pending"},{value:"ready",label:"Ready"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}];function X(){const[u,i]=t.useState(!0),[a,n]=t.useState([]),[c,y]=t.useState("all"),[l,f]=t.useState(""),[x,o]=t.useState(null);t.useEffect(()=>{j()},[]);const j=async()=>{i(!0);try{const s=await p.get("/admin/pre-orders");n(Array.isArray(s.data?.data)?s.data.data:Array.isArray(s.data)?s.data:[])}catch{}finally{i(!1)}},N=async s=>{o(s);try{await p.post(`/admin/pre-orders/${s}/process`),n(r=>r.map(d=>d.id===s?{...d,status:"completed"}:d)),h.success(`Pre-order ${s} processed successfully`)}catch{h.error("Failed to process pre-order")}finally{o(null)}},b=a.length,v=a.filter(s=>s.status==="pending").length,w=a.filter(s=>s.status==="ready").length,S=a.filter(s=>s.status!=="cancelled").reduce((s,r)=>s+(r.deposit_paid||0),0),m=a.filter(s=>s.id.toLowerCase().includes(l.toLowerCase())||s.product.toLowerCase().includes(l.toLowerCase())||s.customer.toLowerCase().includes(l.toLowerCase())?c!=="all"?s.status===c:!0:!1);return u?e.jsx("div",{className:"flex items-center justify-center min-h-96",children:e.jsx(g,{className:"h-8 w-8 animate-spin text-violet-600"})}):e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Pre-Orders"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Manage customer pre-orders and process payments"})]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-violet-100 rounded-lg",children:e.jsx(C,{className:"h-5 w-5 text-violet-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Total Pre-Orders"}),e.jsx("p",{className:"text-2xl font-bold text-gray-900",children:b})]})]})}),e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-yellow-100 rounded-lg",children:e.jsx(P,{className:"h-5 w-5 text-yellow-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Pending"}),e.jsx("p",{className:"text-2xl font-bold text-gray-900",children:v})]})]})}),e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 rounded-lg",children:e.jsx(A,{className:"h-5 w-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Ready to Process"}),e.jsx("p",{className:"text-2xl font-bold text-gray-900",children:w})]})]})}),e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-100 rounded-lg",children:e.jsx(L,{className:"h-5 w-5 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Revenue Collected"}),e.jsxs("p",{className:"text-2xl font-bold text-gray-900",children:["AED ",S.toLocaleString()]})]})]})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-5 space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:_.map(s=>e.jsx("button",{onClick:()=>
1y(s.value),className:`px-4 py-1.5 rounded-full text-sm font-medium transition-colors ${c===s.value?"bg-violet-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:s.label},s.value))}),e.jsxs("div",{className:"relative w-full sm:w-64",children:[e.jsx(D,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx("input",{value:l,onChange:s=>f(s.target.value),placeholder:"Search orders...",className:"w-full pl-9 pr-3 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-violet-500"})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-100",children:[e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Order ID"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Product"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Customer"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Deposit"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Total"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Expected Date"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Status"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Actions"})]})}),e.jsx("tbody",{children:m.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"text-center py-10 text-gray-400",children:"No pre-orders found."})}):m.map(s=>e.jsxs("tr",{className:"border-b border-gray-50 hover:bg-gray-50",children:[e.jsx("td",{className:"py-3 px-2 font-mono text-xs font-medium text-violet-700",children:s.id}),e.jsx("td",{className:"py-3 px-2 font-medium text-gray-900 max-w-40 truncate",title:s.product,children:s.product}),e.jsxs("td",{className:"py-3 px-2",children:[e.jsx("div",{className:"text-gray-900 font-medium",children:s.customer}),e.jsx("div",{className:"text-gray-500 text-xs",children:s.customer_email})]}),e.jsxs("td",{className:"py-3 px-2 text-gray-700",children:["AED ",s.deposit_paid.toLocaleString()]}),e.jsxs("td",{className:"py-3 px-2 font-semibold text-gray-900",children:["AED ",s.total_amount.toLocaleString()]}),e.jsx("td",{className:"py-3 px-2 text-gray-500",children:s.expected_date}),e.jsx("td",{className:"py-3 px-2",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium capitalize ${O[s.status]||"bg-gray-100 text-gray-600"}`,children:s.status})}),e.jsx("td",{className:"py-3 px-2",children:s.status==="ready"?e.jsxs("button",{onClick:()=>N(s.id),disabled:x===s.id,className:"flex items-center gap-1 px-3 py-1.5 bg-violet-600 hover:bg-violet-700 text-white rounded-lg text-xs font-medium transition-colors disabled:opacity-50",children:[x===s.id?e.jsx(g,{className:"h-3 w-3 animate-spin"}):e.jsx(E,{className:"h-3 w-3"}),"Process"]}):s.status==="pending"?e.jsxs("span",{className:"text-xs text-gray-400 flex items-center gap-1",children:[e.jsx(T,{className:"h-3 w-3"})," Awaiting stock"]}):e.jsx("span",{className:"text-xs text-gray-300",children:"â"})})]},s.id))})]})})]})]})}export{X 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.