1import{j as e,t as F,i as L,r as j,an as N,aj as k,aq as O,M as A}from"./index-B5Aoxc7f.js";import{u as E}from"./auth-DCQNNPBD.js";import{A as R,a as q}from"./AdminShell-ubpJOWqi.js";import{g as U}from"./admin-submissions.functions-CnJZzI5d.js";import{D as z}from"./download-BqxYIB2e.js";import{L as G}from"./loader-circle-BavV0jUT.js";import"./dialog-CzbOn1_E.js";import"./input-CaPPmnTN.js";import"./package-Ib0LAcmi.js";import"./flower-2-hJUklDEA.js";import"./info-CDiq_qOh.js";import"./search-C4_LEUwQ.js";import"./auth-middleware-Dz39gAdU.js";function te(){const{user:s,isAdmin:i,loading:o}=E();return e.jsx(R,{hasUser:!!s,isAdmin:i,loading:o,children:e.jsx(q,{children:e.jsx(I,{})})})}const r=s=>`$${N(Number(s)||0)}`;function I(){const s=F(U),{data:i,isLoading:o,isError:a,error:x}=L({queryKey:["order-submissions"],queryFn:()=>s()}),l=i?.rows??[],y=new Date,u=new Date;u.setDate(u.getDate()-30);const b=n=>n.toISOString().slice(0,10),[p,v]=j.useState(b(u)),[h,w]=j.useState(b(y)),_=()=>{const n=new Date(p+"T00:00:00").getTime(),D=new Date(h+"T23:59:59.999").getTime(),C=l.filter(t=>{const d=new Date(t.created_at).getTime();return d>=n&&d<=D}),S=["Received","Name","Email","Phone","Event Date","Delivery Time","Guests","Address","City","Zip","On-site Name","On-site Phone","Add Disposables","Notes","Items","Food Subtotal","Disposables","Delivery Fee","CC Fee","Tax","Tip Choice","Tip Amount","Grand Total","Agreed Terms"],T=t=>{const d=t==null?"":String(t);return/[",\n\r]/.test(d)?`"${d.replace(/"/g,'""')}"`:d},f=[S.join(",")];for(const t of C){const d=(t.lines||[]).map(m=>`${m.quantity}x ${m.name}${m.unitLabel?` (${m.unitLabel})`:""} @ $${N(m.price||0)}`).join(" | ");f.push([new Date(t.created_at).toLocaleString(),t.name,t.email,t.phone,t.event_date,t.delivery_time,t.guests,t.address,t.city,t.zip,t.onsite_name,t.onsite_phone,t.add_disposables?"Yes":"No",t.notes,d,t.food_subtotal,t.disposables,t.delivery_fee,t.cc_fee,t.tax,t.tip_choice,t.tip_amount,t.grand_total,t.agreed_terms?"Yes":"No"].map(T).join(","))}const $=new Blob(["\uFEFF"+f.join(` 2`)],{type:"text/csv;charset=utf-8;"}),g=URL.createObjectURL($),c=document.createElement("a");c.href=g,c.download=`order-submissions_${p}_to_${h}.csv`,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(g)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"font-display text-3xl font-semibold",children:"Order submissions"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Every cart order request is saved here as a backup. Notification emails are also sent to [email protected]. Records are automatically deleted after 60 days."})]}),e.jsxs("div",{className:"mb-6 rounded-2xl border border-border bg-card p-4 flex flex-wrap items-end gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-wider text-muted-foreground mb-1",children:"From"}),e.jsx("input",{type:"date",value:p,onChange:n=>v(n.target.value),className:"rounded-md border border-border bg-background px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-wider text-muted-foreground mb-1",children:"To"}),e.jsx("input",{type:"date",value:h,onChange:n=>w(n.target.value),className:"rounded-md border border-border bg-background px-3 py-2 text-sm"})]}),e.jsxs("button",{type:"button",onClick:_,disabled:o||l.length===0,className:"inline-flex items-center gap-2 rounded-md bg-primary text-primary-foreground px-4 py-2 text-sm font-medium hover:opacity-90 disabled:opacity-50",children:[e.jsx(z,{className:"h-4 w-4"})," Export CSV"]})]}),o&&e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-8 text-center text-muted-foreground",children:[e.jsx(G,{className:"h-5 w-5 animate-spin inline mr-2"})," Loadingâ¦"]}),a&&e.jsxs("div",{className:"rounded-2xl border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive",children:["Failed to load: ",x?.message]}),!o&&!a&&l.length===0&&e.jsx("div",{className:"rounded-2xl border border-border bg-card p-8 text-center text-muted-foreground",children:"No order submissions yet."}),l.length>0&&e.jsx("div",{className:"rounded-2xl border border-border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary/50 text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-8 px-2 py-3"}),e.jsx("th",{className:"text-left px-4 py-3",children:"Received"}),e.jsx("th",{className:"text-left px-4 py-3",children:"Customer"}),e.jsx("th",{className:"text-left px-4 py-3",children:"Event"}),e.jsx("th",{className:"text-right px-4 py-3",children:"Total"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:l.map(n=>e.jsx(P,{row:n},n.id))})]})})})]})}function P({row:s}){const[i,o]=j.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"align-top hover:bg-secondary/20 cursor-pointer",onClick:()=>o(!i),children:[e.jsx("td",{className:"px-2 py-3 text-muted-foreground",children:i?e.jsx(k,{className:"h-4 w-4"}):e.jsx(O,{className:"h-4 w-4"})}),e.jsx("td",{className:"px-4 py-3 whitespace-nowrap text-muted-foreground",children:new Date(s.created_at).toLocaleStr
2ing()}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-medium",children:s.name}),e.jsxs("a",{href:`mailto:${s.email}`,onClick:a=>a.stopPropagation(),className:"text-primary hover:underline inline-flex items-center gap-1 text-xs",children:[e.jsx(A,{className:"h-3 w-3"})," ",s.email]}),s.phone&&e.jsx("div",{className:"text-muted-foreground text-xs",children:s.phone})]}),e.jsxs("td",{className:"px-4 py-3 text-xs text-muted-foreground",children:[s.event_date&&e.jsxs("div",{children:["Date: ",e.jsxs("span",{className:"text-foreground",children:[s.event_date,s.delivery_time&&` @ ${s.delivery_time}`]})]}),s.guests&&e.jsxs("div",{children:["Guests: ",e.jsx("span",{className:"text-foreground",children:s.guests})]}),(s.city||s.zip)&&e.jsx("div",{children:[s.city,s.zip].filter(Boolean).join(", ")})]}),e.jsx("td",{className:"px-4 py-3 text-right font-semibold tabular-nums",children:r(s.grand_total)})]}),i&&e.jsxs("tr",{className:"bg-secondary/20",children:[e.jsx("td",{}),e.jsx("td",{colSpan:4,className:"px-4 py-4",children:e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase text-muted-foreground mb-2",children:"Delivery"}),e.jsxs("dl",{className:"text-xs space-y-1",children:[s.address&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Address:"})," ",s.address]}),(s.city||s.zip)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"City/Zip:"})," ",[s.city,s.zip].filter(Boolean).join(", ")]}),s.onsite_name&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"On-site:"})," ",s.onsite_name," ",s.onsite_phone&&`(${s.onsite_phone})`]}),s.add_disposables&&e.jsx("div",{className:"text-foreground",children:"+ Disposables included"}),s.notes&&e.jsxs("div",{className:"mt-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Notes:"}),e.jsx("div",{className:"whitespace-pre-wrap mt-1",children:s.notes})]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase text-muted-foreground mb-2",children:"Items"}),e.jsx("ul",{className:"text-xs space-y-1",children:(s.lines||[]).map((a,x)=>e.jsxs("li",{className:"flex justify-between gap-3",children:[e.jsxs("span",{children:[a.quantity,"Ã ",a.name,a.unitLabel?` (${a.unitLabel})`:""]}),e.jsx("span",{className:"tabular-nums text-muted-foreground",children:r((a.price||0)*(a.quantity||0))})]},x))}),e.jsx("h4",{className:"text-xs font-semibold uppercase text-muted-foreground mt-4 mb-2",children:"Totals"}),e.jsxs("dl",{className:"text-xs space-y-0.5",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Food"}),e.jsx("span",{className:"tabular-nums",children:r(s.food_subtotal)})]}),(s.disposables||0)>0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Disposables"}),e.jsx("span",{className:"tabular-nums",children:r(s.disposables)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Delivery"}),e.jsx("span",{className:"tabular-nums",children:r(s.delivery_fee)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"CC fee"}),e.jsx("span",{className:"tabular-nums",children:r(s.cc_fee)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Tax"}),e.jsx("span",{className:"tabular-nums",children:r(s.tax)})]}),(s.tip_amount||0)>0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Gratuity",s.tip_choice&&s.tip_choice!=="custom"?` (${s.tip_choice}%)`:""]}),e.jsx("span",{className:"tabular-nums",children:r(s.tip_amount)})]}),e.jsxs("div",{className:"flex justify-between border-t border-border pt-1 mt-1 font-semibold",children:[e.jsx("span",{children:"Total"}),e.jsx("span",{className:"tabular-nums",children:r(s.grand_total)})]})]})]})]})})]})]})}export{te as component};
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.