1import{r,j as e,L as D}from"./index-hn8V0v61.js";import{A as z}from"./AdminLayout-q01PpU6r.js";import{C as h}from"./Card-CQu9InO1.js";import{B as u}from"./Button-CYNSXS9X.js";import{S as O}from"./Select-CYwQOEls.js";import{M as A}from"./Modal-B3qdet6d.js";import{B}from"./Badge-Cc3oj2xH.js";import{f as F,g as $}from"./badgeUtils-C3vsJNP3.js";import{m as L,B as P}from"./orders-DPQAeQzg.js";import"./scrollLock-COE6sjjz.js";const T=[{value:"",label:"All Statuses"},{value:"pending_verification",label:"Pending Verification"},{value:"pending",label:"Pending"},{value:"processing",label:"Processing"},{value:"invoiced",label:"Invoiced"},{value:"paid",label:"Paid"},{value:"fulfilled",label:"Fulfilled"},{value:"cancelled",label:"Cancelled"}];function G(){const[n,o]=r.useState([]),[j,p]=r.useState(!0),[x,N]=r.useState(""),[s,i]=r.useState(new Set),[b,c]=r.useState(!1),[m,g]=r.useState(!1),[y,d]=r.useState(null),f=async()=>{p(!0);try{const t=await L({status:x||void 0,page:1,pageSize:100});if(t.success&&t.data){const a=t.data;o(a.items??[])}else o([])}catch(t){console.error("Failed to fetch orders:",t),o([])}finally{p(!1)}};r.useEffect(()=>{f(),i(new Set)},[x]);const v=t=>{i(a=>{const l=new Set(a);return l.has(t)?l.delete(t):l.add(t),l})},S=()=>{s.size===n.length?i(new Set):i(new Set(n.map(t=>t.id)))},C=async()=>{g(!0);try{const t=Array.from(s),a=await P(t);if(a.success&&a.data){const l=Object.keys(a.data.failed).length;d(l===0?`Deleted ${a.data.deletedCount} order(s).`:`Deleted ${a.data.deletedCount} order(s). ${l} failed â check server logs.`),i(new Set),c(!1),f()}else d(`Failed to delete: ${a.error||"Unknown error"}`)}catch(t){d(`Failed to delete: ${t instanceof Error?t.message:"Unknown error"}`)}finally{g(!1)}},k=t=>new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),w=t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t);return e.jsxs(z,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(D,{to:"/admin/settings",className:"text-sm text-blue-600 hover:underline",children:"â Settings"}),e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mt-1",children:"Data Cleanup"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Permanently delete test orders. Use sparingly."})]})}),e.jsx(h,{children:e.jsxs("div",{className:"rounded-md bg-red-50 border border-red-200 p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-red-800",children:"â Destructive action"}),e.jsxs("ul",{className:"mt-2 text-sm text-red-700 list-disc pl-5 space-y-1",children:[e.jsxs("li",{children:["Deleted orders are ",e.jsx("strong",{children:"permanently removed"})," from Firestore â there is no undo."]}),e.jsxs("li",{children:["This does ",e.jsx("strong",{children:"not"})," remove related records in QuickBooks (invoices/estimates) or Thinkific (enrollments). Those must be cleaned up in their respective systems."]}),e.jsx("li",{children:"Customers will no longer be able to look up these order numbers."}),e.jsx("li",{children:"Intended for clearing test data, not production orders."})]})]})}),y&&e.jsxs(h,{children:[e.jsx("p",{className:"text-sm",children:y}),e.jsx("button",{onClick:()=>d(null),className:"text-xs text-gray-500 hover:text-gray-700 mt-2",children:"Dismiss"})]}),e.jsxs(h,{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsx("div",{className:"flex-1 max-w-xs",children:e.jsx(O,{label:"Filter by status",value:x,onChange:t=>N(t.target.value),options:T})}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm text-gray-600",children:[s.size," selected"]}),e.jsxs(u,{variant:"primary",onClick:()=>c(!0),disabled:s.size===0,children:["Delete ",s.size>0?`${s.size} order${s.size===1?"":"s"}`:""]})]})]}),j?e.jsx("p",{className:"text-sm text-gray-500 py-8 text-center",children:"Loadingâ¦"}):n.length===0?e.jsx("p",{className:"text-sm text-gray-500 py-8 text-center",children:"No orders match the filter."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left",children:e.jsx("input",{type:"checkbox",checked:s.size>0&&s.size===n.length,onChange:S,className:"h-4 w-4 text-blue-600 rounded border-gray-300"})}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Order #"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Customer"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"School"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Status"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-gray-500 uppercase",children:"Total"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Created"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:n.map(t=>e.jsxs("tr",{className:s.has(t.id)?"bg-red-50":"hover:bg-gray-50",children:[e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{type:"checkbox",checked:s.has(t.id),onChange:()=>v(t.id),className:"h-4 w-4 text-blue-600 rounded border-gray-300"})}),e.jsx("td",{className:"px-3 py-2 text-sm font-mono text-gray-900",children:t.orderNumber}),e.jsx("td",{className:"px-3 py-2 text-sm text-gray-700",children:t.customerName}),e.jsx("td",{className:"px-3 py-2 text-sm text-gray-700",children:t.schoolName}),e.jsx("td",{className:"px-3 py-2 text-sm",children:e.jsx(B,{variant:$
1(t.status),children:F(t.status)})}),e.jsx("td",{className:"px-3 py-2 text-sm text-right text-gray-900",children:w(t.total)}),e.jsx("td",{className:"px-3 py-2 text-sm text-gray-500",children:k(t.createdAt)})]},t.id))})]})})]})]}),e.jsx(A,{isOpen:b,onClose:()=>m?null:c(!1),title:"Confirm deletion",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-gray-700",children:["You are about to ",e.jsxs("strong",{children:["permanently delete ",s.size," order",s.size===1?"":"s"]}),". This cannot be undone."]}),e.jsx("p",{className:"text-sm text-gray-700",children:"Any related records in QuickBooks or Thinkific will remain and may need to be cleaned up manually."}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx(u,{variant:"outline",onClick:()=>c(!1),disabled:m,children:"Cancel"}),e.jsxs(u,{variant:"primary",onClick:C,loading:m,children:["Delete ",s.size," order",s.size===1?"":"s"]})]})]})})]})}export{G as AdminDataCleanup};
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.