1import{r as i,j as e,s as S}from"./index-DeJ875KO.js";import{R as A}from"./Filterleiste-D-uExNFA.js";const L={invoice:"Rechnung",twint:"Twint",cash:"Bar"},_={pickup:"Abholung",delivery:"Lieferung"},j=["processing","paid","delivered","completed"],f={processing:"In Bearbeitung",paid:"Bezahlt",delivered:"Ausgeliefert",completed:"Abgeschlossen"},B={processing:"bg-amber-100 text-amber-700 dark:bg-amber-950/40 dark:text-amber-300",paid:"bg-blue-100 text-blue-700 dark:bg-blue-950/40 dark:text-blue-300",delivered:"bg-green-100 text-green-700 dark:bg-green-950/40 dark:text-green-300",completed:"bg-zinc-200 text-zinc-600 dark:bg-zinc-700 dark:text-zinc-300"};function m(a){return j.includes(a??"")?a:"processing"}async function k(a,c={}){const{data:{session:d}}=await S.auth.getSession();return fetch(a,{...c,headers:{"Content-Type":"application/json",Authorization:`Bearer ${d?.access_token??""}`,...c.headers??{}}})}function E(){const[a,c]=i.useState([]),[d,u]=i.useState(!0),[p,N]=i.useState(null),[v,h]=i.useState(null),[l,y]=i.useState("active"),x=i.useCallback(async()=>{u(!0);const n=await(await k("/api/admin/shop/orders")).json();c(Array.isArray(n)?n:[]),u(!1)},[]);i.useEffect(()=>{x()},[x]);async function w(t,n){h(t),c(r=>r.map(o=>o.id===t?{...o,status:n}:o));const s=await k("/api/admin/shop/orders",{method:"PUT",body:JSON.stringify({id:t,status:n})});if(!s.ok){const r=await s.json().catch(()=>({}));alert(r.error??"Aktualisierung fehlgeschlagen."),await x()}h(null)}if(d)return e.jsx("div",{className:"animate-pulse h-48 bg-zinc-100 dark:bg-zinc-800 rounded-xl"});const b=a.filter(t=>m(t.status)!=="completed"),g=a.filter(t=>m(t.status)==="completed"),z=l==="active"?b:g;return e.jsxs("div",{className:"max-w-4xl",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx("h1",{className:"text-xl font-bold text-zinc-900 dark:text-zinc-100",children:"Bestellungen"})}),e.jsx(A,{aktiv:l,onWechsel:y,reiter:[{key:"active",label:"Aktive Bestellungen",anzahl:b.length},{key:"archive",label:"Archiv",anzahl:g.length}]}),z.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-zinc-200 dark:border-zinc-700 p-8 text-center",children:e.jsx("p",{className:"text-zinc-400 dark:text-zinc-500 text-sm",children:l==="active"?"Keine offenen Bestellungen.":"Noch nichts archiviert."})}):e.jsx("div",{className:"space-y-2",children:z.map(t=>{const n=m(t.status);return e.jsxs("div",{className:"rounded-xl border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-800/40 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>N(s=>s===t.id?null:t.id),className:"w-full flex items-center gap-4 px-5 py-4 text-left hover:bg-zinc-50 dark:hover:bg-zinc-800/60 transition-colors",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-xs font-mono text-zinc-400 dark:text-zinc-500",children:["#",t.id.slice(0,8).toUpperCase()]}),e.jsx("span",{className:"text-sm font-medium text-zinc-900 dark:text-zinc-100",children:t.customer_name||t.customer_email}),t.customer_name&&e.jsx("span",{className:"text-xs text-zinc-400 dark:text-zinc-500",children:t.customer_email}),e.jsx("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${B[n]}`,children:f[n]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[e.jsx("span",{className:"text-xs text-zinc-500 dark:text-zinc-400",children:new Date(t.created_at).toLocaleString("de-CH",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-700 text-zinc-600 dark:text-zinc-300",children:L[t.payment_method]??t.payment_method}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-700 text-zinc-600 dark:text-zinc-300",children:_[t.fulfillment]??t.fulfillment})]})]}),e.jsxs("span",{className:"shrink-0 text-sm font-bold text-zinc-900 dark:text-zinc-100",children:["CHF ",Number(t.total).toFixed(2)]}),e.jsx("svg",{className:`w-4 h-4 text-zinc-400 shrink-0 transition-transform ${p===t.id?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p===t.id&&e.jsxs("div",{className:"px-5 pb-4 pt-1 border-t border-zinc-100 dark:border-zinc-700 space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[t.items.map((s,r)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"text-zinc-700 dark:text-zinc-300",children:[s.name," à ",s.quantity]}),e.jsxs("span",{className:"text-zinc-500 dark:text-zinc-400",children:["CHF ",(s.price*s.quantity).toFixed(2)]})]},r)),Number(t.shipping)>0&&e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-zinc-700 dark:text-zinc-300",children:"Versandkosten"}),e.jsxs("span",{className:"text-zinc-500 dark:text-zinc-400",children:["CHF ",Number(t.shipping).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-xs font-semibold pt-1.5 border-t border-zinc-100 dark:border-zinc-700",children:[e.jsx("span",{className:"text-zinc-900 dark:text-zinc-100",children:"Total"}),e.jsxs("span",{className:"text-zinc-900 dark:text-zinc-100",children:["CHF ",Number(t.total).toFixed(2)]})]})]}),t.delivery_address&&e.jsxs("p",{className:"text-xs text-zinc-500 dark:text-zinc-400",children:[e.jsx("strong",{children:"Lieferadresse:"})," ",t.delivery_address]}),e.jsxs("div",{className:"pt-2 border-t border-zinc-100 dark:border-zinc-700 flex items-center gap-3",children:[e.jsx("label",{className:"text-xs font-medium text-zinc-600 dark:text-zinc-400",children:"Status"}),e.jsx("select",{value:n,disabled:v===t.id,onChange:s=>w(t.id,s.target.value),className:"text-xs px-3 py-1.5 rounded-lg border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 focus:outline-none focus:ring-2 focus:ring-red-500 disabled:opacity-50",children:j.map(s=>e.jsx("option",{value:s,children:f[s]},s))}),n!=="completed"&&e.jsx("span",{className:"text-xs text-zinc-400 dark:text-zinc-500",children:"â «Abgeschlossen» verschiebt die Bestellung ins Archiv."})]})]})]},t.id)})})]})}export{E as AdminShopOrders};
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.