PageSourceSearch

https://unit10.audio/assets/OrderAdmin-ClxZV85M.js

js unit10.audio collected 2026-10-09 22:19:08 UTC 35,830 bytes, 1 lines download raw bytes

1import{b as ue,r,j as e,L as me,A as oe,m as B}from"./vendor-B5DssOfd.js";import{D as fe}from"./DashboardLayout-D0gZrLSq.js";import{C as be}from"./ConfirmModal-C505HDNp.js";import{q as he}from"./index-ClHmr1ee.js";import{u as ye}from"./i18n-uURfBduE.js";const x="https://api.rstcc.net".replace(/\/$/,""),de={OFFERTE:"bg-violet-500/10 text-violet-400 border-violet-500/20",PENDING:"bg-orange-500/10 text-orange-500 border-orange-500/20",WEB_BETALING:"bg-cyan-500/10 text-cyan-400 border-cyan-500/20",PROCESSING:"bg-blue-500/10 text-blue-500 border-blue-500/20",SHIPPED:"bg-purple-500/10 text-purple-500 border-purple-500/20",COMPLETED:"bg-green-500/10 text-green-500 border-green-500/20",CANCELLED:"bg-red-500/10 text-red-500 border-red-500/20",GEFACTUREERD:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",BETAALD:"bg-green-500/10 text-green-400 border-green-500/20"};function Se(){var ne,le;const{t:c}=ye(),A=ue(),U={OFFERTE:c("admin.orders.statusOfferte"),PENDING:c("admin.orders.statusPending"),WEB_BETALING:c("admin.orders.statusWebBetaling"),PROCESSING:c("admin.orders.statusProcessing"),SHIPPED:c("admin.orders.statusShipped"),COMPLETED:c("admin.orders.statusCompleted"),CANCELLED:c("admin.orders.statusCancelled"),INVOICED:c("admin.orders.statusInvoiced"),GEFACTUREERD:c("admin.orders.statusInvoiced"),BETAALD:c("admin.orders.statusBetaald")},[m,Q]=r.useState([]),[q,Y]=r.useState(!0),[N,X]=r.useState(!1),[k,ee]=r.useState([]),[u,I]=r.useState("all"),[p,G]=r.useState(""),[te,M]=r.useState(null),[L,b]=r.useState(null),[ae,w]=r.useState(!1),[l,y]=r.useState(null),[S,W]=r.useState(null),[_,E]=r.useState(null),[z,V]=r.useState("all"),[J,pe]=r.useState("nl"),[f,C]=r.useState("client"),[h,F]=r.useState(""),[O,P]=r.useState({show:!1,title:"",message:"",status:"FINE"}),D=(t,o,d="FINE")=>{P({show:!0,title:t,message:o,status:d}),setTimeout(()=>P(a=>({...a,show:!1})),5e3)},T={Authorization:`Token ${localStorage.getItem("token")||""}`},Z={...T,"Content-Type":"application/json"},se=()=>{Y(!0),fetch(`${x}/api/orders/`,{headers:T}).then(t=>t.ok?t.json():[]).then(t=>Q(t)).catch(()=>{}).finally(()=>Y(!1))};r.useEffect(()=>{se()},[]);const re=async t=>{M(t),await fetch(`${x}/api/orders/${t}/void/`,{method:"DELETE",headers:T}),Q(o=>o.filter(d=>d.id!==t)),M(null)},H=async t=>{var o;E(null),y(t),W(null);try{const d={brand:z,lang:J,recipient_type:f};f==="alternative"&&h&&(d.alternative_email=h);const a=await fetch(`${x}/api/orders/${t}/send-view-link/`,{method:"POST",headers:Z,body:JSON.stringify(d)}),s=await a.json();if(a.ok){W(t);const i=f==="self"?"jezelf":f==="alternative"?h:((o=m.find(n=>n.id===t))==null?void 0:o.user_details.email)||"klant";D("E-mail verstuurd",`Link verstuurd naar ${i}`,"FINE"),setTimeout(()=>W(null),5e3)}else D("Fout",s.error||"E-mail kon niet worden verstuurd.","ACTION")}catch{D("Fout","Netwerkfout bij versturen.","ACTION")}finally{y(null)}},g=p.trim().toLowerCase(),ie=m.filter(t=>{var o;if(k.length>0&&!k.includes(t.status)||u==="private"&&!t.is_private||u==="public"&&t.is_private)return!1;if(g){const d=t.user_details||{};if(!`${d.first_name||""} ${d.last_name||""} ${d.email||""} ${d.zipcode||""} ${d.place||""} ${t.custom_description||""} ${((o=t.product_details)==null?void 0:o.title)||""}`.toLowerCase().includes(g))return!1}return!0}),R=k.length+(u!=="all"?1:0)+(g?1:0),$=["OFFERTE","PENDING","WEB_BETALING","PROCESSING","SHIPPED","COMPLETED","CANCELLED","GEFACTUREERD","BETAALD"];return e.jsxs(fe,{children:[e.jsxs("div",{className:"px-12 py-8 space-y-8",children:[e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h1",{className:"text-5xl font-black uppercase italic tracking-tighter text-on-surface",children:["Order ",e.jsx("span",{className:"text-primary",children:"Management"})]}),e.jsx("p",{className:"text-on-surface-variant font-medium opacity-60 italic text-lg tracking-wide",children:"Beheer offertes, bestellingen en facturen."})]}),e.jsxs("div",{className:"relative flex items-center space-x-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] absolute left-3 top-1/2 -translate-y-1/2 text-on-surface-variant/40 pointer-events-none",children:"search"}),e.jsx("input",{value:p,onChange:t=>G(t.target.value),placeholder:"Zoek op naam, postcode of e-mail…",className:"w-64 pl-10 pr-3 py-4 rounded-2xl border border-outline-variant/20 bg-surface-container-high text-sm text-on-surface placeholder:text-on-surface-variant/40 focus:outline-none focus:border-primary/40"})]}),e.jsxs(me,{to:"/admin/dashboard",className:"flex items-center space-x-2 px-5 py-4 rounded-2xl border border-outline-variant/20 bg-surface-container-high text-on-surface-variant font-black uppercase tracking-widest text-[11px] hover:text-primary hover:border-primary/30 transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"arrow_back"}),e.jsx("span",{children:"Admin Dashboard"})]}),e.jsxs("button",{onClick:()=>w(!0),className:"flex items-center space-x-2 px-6 py-4 bg-primary text-on-primary rounded-2xl font-black uppercase tracking-widest text-[11px] shadow-lg shadow-primary/20 hover:scale-[1.02] active:scale-[0.98] transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"add"}),e.jsx("span",{children:"Nieuw"})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>X(t=>
1!t),className:`relative flex items-center gap-2 px-5 py-4 rounded-2xl border font-black uppercase tracking-widest text-[11px] transition-all ${R>0?"bg-primary/10 border-primary/30 text-primary":"border-outline-variant/20 bg-surface-container-high text-on-surface-variant hover:text-primary hover:border-primary/30"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"filter_list"}),e.jsx("span",{children:"Filter"}),R>0&&e.jsx("span",{className:"w-5 h-5 rounded-full bg-primary text-on-primary text-[9px] font-black flex items-center justify-center",children:R})]}),e.jsx(oe,{children:N&&e.jsxs(B.div,{initial:{opacity:0,y:8,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.97},className:"absolute right-0 top-full mt-2 w-80 bg-surface-container border border-outline-variant/20 rounded-2xl shadow-2xl z-30 p-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"Filters"}),R>0&&e.jsx("button",{onClick:()=>{ee([]),I("all")},className:"text-[9px] font-black text-primary hover:underline uppercase tracking-widest",children:"Wissen"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40",children:"Status"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:$.map(t=>e.jsx("button",{onClick:()=>ee(o=>o.includes(t)?o.filter(d=>d!==t):[...o,t]),className:`px-3 py-1.5 rounded-xl text-[9px] font-black uppercase tracking-widest border transition-all ${k.includes(t)?de[t]||"bg-primary/10 text-primary border-primary/20":"border-outline-variant/20 text-on-surface-variant/60 hover:border-outline-variant/40"}`,children:U[t]||t},t))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40",children:"Zichtbaarheid offerte"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:["all","public","private"].map(t=>e.jsx("button",{onClick:()=>I(t),className:`py-2 rounded-xl text-[9px] font-black uppercase tracking-widest border transition-all truncate ${u===t?"bg-primary/10 text-primary border-primary/20":"border-outline-variant/20 text-on-surface-variant/60 hover:border-outline-variant/40"}`,children:t==="all"?"Alle":t==="public"?"Zichtbaar":"Verborgen"},t))})]})]})})]})]})]}),e.jsx("div",{className:"flex gap-3 flex-wrap",children:["OFFERTE","PENDING","GEFACTUREERD"].map(t=>{const o=m.filter(d=>d.status===t).length;return o?e.jsxs("div",{className:`flex items-center gap-2 px-4 py-2 rounded-2xl border text-[10px] font-black uppercase tracking-widest ${de[t]}`,children:[e.jsx("span",{children:U[t]}),e.jsxs("span",{className:"opacity-60",children:["×",o]})]},t):null})}),e.jsx("div",{className:"space-y-3",children:q?e.jsx("div",{className:"flex justify-center py-24",children:e.jsx("div",{className:"w-10 h-10 border-2 border-primary/30 border-t-primary rounded-full animate-spin"})}):ie.length===0?e.jsx("div",{className:"text-center py-24 text-on-surface-variant/40 italic text-sm",children:"Geen bestellingen gevonden."}):e.jsx(oe,{mode:"popLayout",children:ie.map((t,o)=>{var i,n,v;const d=((i=t.product_details)==null?void 0:i.title)||t.custom_description||"—",a=((n=t.product_details)==null?void 0:n.art_no)||"HANDMATIG",s=parseFloat(t.price_at_order)*t.quantity+(t.lines||[]).reduce((ce,K)=>ce+parseFloat(K.price_at_order)*K.quantity,0);return e.jsxs(B.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},exit:{opacity:0,x:-16},transition:{delay:o*.02},className:"bg-surface-container rounded-[1.5rem] border border-outline-variant/10 p-5 flex items-center gap-5 relative overflow-hidden",children:[e.jsx("div",{className:`absolute left-0 top-0 bottom-0 w-1 rounded-l-[1.5rem] ${((v=de[t.status])==null?void 0:v.split(" ")[1])||"bg-gray-400"}`}),e.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-container-high border border-outline-variant/10 flex items-center justify-center flex-shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-xl text-on-surface-variant/40",children:t.status==="OFFERTE"?"description":"receipt_long"})}),e.jsxs("div",{className:"flex-1 min-w-0 grid grid-cols-2 md:grid-cols-5 ga
1p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 mb-0.5",children:"Klant"}),e.jsxs("div",{className:"text-sm font-black truncate",children:[t.user_details.first_name," ",t.user_details.last_name]}),e.jsx("div",{className:"text-[10px] text-on-surface-variant/50 truncate",children:t.user_details.email})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 mb-0.5",children:"Product / Omschrijving"}),e.jsx("div",{className:"text-sm font-black text-primary truncate",children:d}),e.jsxs("div",{className:"text-[10px] text-on-surface-variant/50",children:[a," · ×",t.quantity]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 mb-0.5",children:"Totaal incl. BTW"}),e.jsxs("div",{className:"text-sm font-black",children:["€",s.toFixed(2)]}),e.jsx("div",{className:"text-[10px] text-on-surface-variant/50",children:new Date(t.date).toLocaleDateString("nl-NL",{day:"2-digit",month:"short",year:"numeric"})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 mb-0.5",children:"Status"}),e.jsx("span",{className:`inline-flex px-3 py-1 rounded-full text-[9px] font-black uppercase tracking-widest border ${de[t.status]||"bg-surface-variant text-on-surface-variant border-outline-variant/20"}`,children:U[t.status]||t.status})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 mb-0.5",children:"Zichtbaar"}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-[9px] font-black border ${t.is_private?"bg-gray-500/10 text-gray-400 border-gray-500/20":"bg-green-500/10 text-green-400 border-green-500/20"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[11px]",children:t.is_private?"visibility_off":"visibility"}),t.is_private?"Verborgen":"Zichtbaar"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>E(t.id),disabled:l===t.id,title:"Stuur link naar klant",className:`flex items-center gap-1.5 px-3 py-2 border rounded-xl text-[9px] font-black uppercase tracking-widest transition-all disabled:opacity-40 ${S===t.id?"bg-green-500/10 text-green-400 border-green-500/20":"bg-surface-container-high text-on-surface-variant border-outline-variant/20 hover:text-primary hover:border-primary/30"}`,children:l===t.id?e.jsx("div",{className:"w-3.5 h-3.5 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}):e.jsx("span",{className:"material-symbols-outlined text-sm",children:S===t.id?"check":"forward_to_inbox"})}),e.jsxs("button",{onClick:()=>A(`/admin/orders/${t.id}`),className:"flex items-center gap-1.5 px-3 py-2 bg-primary/10 text-primary border border-primary/20 rounded-xl text-[9px] font-black uppercase tracking-widest hover:bg-primary/20 transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"edit"}),"Bewerk"]}),e.jsx("button",{onClick:()=>b(t.id),disabled:te===t.id,className:"flex items-center gap-1.5 px-3 py-2 bg-red-500/10 text-red-500 border border-red-500/20 rounded-xl text-[9px] font-black uppercase tracking-widest hover:bg-red-500/20 transition-all disabled:opacity-40",children:te===t.id?e.jsx("div",{className:"w-3.5 h-3.5 border-2 border-red-400/30 border-t-red-400 rounded-full animate-spin"}):e.jsx("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})]},t.id)})})})]}),e.jsx(be,{open:L!==null,title:"Bestelling verwijderen",message:"De bestelling wordt permanent verwijderd. Dit kan niet ongedaan worden.",confirmLabel:"Verwijderen",danger:!0,onConfirm:()=>{const t=L;b(null),re(t)},onCancel:()=>b(null)}),e.jsx(oe,{children:ae&&e.jsx(ge,{headers:Z,onClose:()=>w(!1),onCreated:t=>A(`/admin/orders/${t}`)})}),e.jsx(oe,{children:_!==null&&e.jsx(B.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:t=>{t.target===t.currentTarget&&E(null)},children:e.jsxs(B.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"bg-surface-container border border-outline-variant/20 rounded-[2rem] p-10 w-full max-w-lg shadow-2xl space-y-7",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-2xl",children:"forward_to_inbox"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black text-base",children:"Stuur link naar klant"}),e.jsx("div",{className:"text-[11px] text-on-surface-variant/60 mt-0.5",children:((ne=m.find(t=>t.id===_))==null?void 0:ne.user_details.email)||""})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"Verzenden naar"}),e.jsx("div",{className:"flex gap-2",children:[{value:"client",label:"Klant",icon:"person"},{value:"self",label:"Mijzelf",icon:"manage_accounts"},{value:"alternative",label:"Alternatief",icon:"alternate_email"}].map(t=>e.jsxs("button",{onClick:()=>C(t.value),className:`flex-1 flex flex-col items-center gap-1 px-3 py-2.5 rounded-xl border text-[10px] font-black uppercase tracking-widest transition-all ${f===t.value?"bg-primary/10 border-primary/40 text-primary":"border-outline-variant/20 text-on-surface-variant/50 hover:border-outline-variant/40"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-base",children:t.icon}),t.label]},t.value))}),f==="client"&&e.jsx("p",{className:"text-[10px] text-on-surface-variant/50 px-1",children:((le=m.find(t=>t.id===_))==null?void 0:le.user_details.email)||"— geen e-mailadres"}),f==="alternative"&&e.jsx("input",{type:"email",value:h,onChange:t=>F(t.target.value),placeholder:"[email protected]",className:"w-full bg-black/20 border border-outline-variant/20 rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:border-primary/50"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"E-mail layout"}),e.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:["all","rstcc","tms","unit10"].map(t=>e.jsx("button",{onClick:()=>V(t),className:`py-3 rounded-xl text-[10px] font-black uppercase tracking-widest border transition-all ${z===t?"bg-primary/10 text-primary border-primary/30":"border-outline-variant/20 text-on-surface-variant/60 hover:border-outline-variant/40"}`,children:t==="all"?"Standaard":t.toUpperCase()},t))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"Taal"}),e.jsx("div",{className:"flex gap-2",children:["nl","en"].map(t=>e.jsx("button",{onClick:()=>pe(t),className:`flex-1 py-3.5 rounded-xl text-[11px] font-black uppercase tracking-widest border transition-all ${J===t?"bg-primary/10 text-primary border-primary/30":"border-outline-variant/20 text-on-surface-variant/60 hover:border-outline-variant/40"}`,children:t==="nl"?"🇳🇱 Nederlands":"🇬🇧 English"},t))})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>E(null),className:"flex-1 py-3 rounded-2xl bg-surface-container-high border border-outline-variant/20 text-[10px] font-black uppercase tracking-widest hover:bg-surface-container-highest transition-all",children:"Annuleer"}),e.jsxs("button",{onClick:()=>H(_),className:"flex-1 flex items-center justify-center gap-2 py-3 rounded-2xl bg-primary text-on-primary text-[10px] font-black uppercase tracking-widest hover:bg-primary/90 transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"send"}),"Verstuur"]})]})]})})}),e.jsx(he,{show:O.show,onClose:()=>P(t=>({...t,show:!1})),title:O.title,message:O.message,status:O.status})]})}function ge({headers:c,onClose:A,onCreated:U}){const[m,Q]=r.useState("order"),[q,Y]=r.useState(!1),[N,X]=r.useState("lines"),[k,ee]=r.useState([]),[u,I]=r.useState(""),[p,G]=r.useState(null),[te,M]=r.useState(!1),[L,b]=r.useState([]),[ae,w]=r.useState(""),[l,y]=r.useState(null),[S,W]=r.useState({tms:!1,unit10:!1,rst
1cc:!1}),[_,E]=r.useState(!1),[z,V]=r.useState(""),[J,pe]=r.useState([]),f=()=>({id:crypto.randomUUID(),productId:null,productTitle:"",artNo:"",description:"",quantity:1,price:"",query:"",results:[],showResults:!1}),[C,h]=r.useState([f()]),[F,O]=r.useState(""),[P,D]=r.useState(!1),[xe,T]=r.useState(""),[Z,se]=r.useState(!1),[re,H]=r.useState("");r.useEffect(()=>{fetch(`${x}/api/admin/users/`,{headers:c}).then(a=>a.ok?a.json():[]).then(a=>ee(Array.isArray(a)?a:a.results||[])),fetch(`${x}/api/products/?limit=500`,{headers:c}).then(a=>a.ok?a.json():[]).then(a=>pe(Array.isArray(a)?a:a.results||[]))},[]);const g=u.length>1?k.filter(a=>`${a.first_name} ${a.last_name} ${a.email} ${a.username}`.toLowerCase().includes(u.toLowerCase())).slice(0,8):[],ie=u.length>2&&g.length===0&&!p;r.useEffect(()=>{if(u.length<=2||p||g.length>0)return;b([]),w("");const a=u,s=setTimeout(async()=>{M(!0);try{const i=encodeURIComponent(a),n=await Promise.all([fetch(`${x}/api/wefact/klanten/?q=${i}`,{headers:c}),fetch(`${x}/api/wefact/klanten/?bedrijf=${i}`,{headers:c}),fetch(`${x}/api/wefact/klanten/?stad=${i}`,{headers:c}),fetch(`${x}/api/wefact/klanten/?postcode=${i}`,{headers:c})]);if(n.every(j=>!j.ok)){w("Zoekfout");return}const v=await Promise.all(n.map(j=>j.json())),ce=new Set,K=v.flatMap(j=>j.debtors||[]).filter(j=>ce.has(j.code)?!1:(ce.add(j.code),!0));b(K),K.length===0&&w("Geen klanten gevonden in WeFact.")}catch{w("Netwerkfout")}finally{M(!1)}},500);return()=>clearTimeout(s)},[u,k,p]);const R=async()=>{if(l){E(!0),V("");try{const a=await fetch(`${x}/api/admin/users/`,{method:"POST",headers:c,body:JSON.stringify({email:l.email,first_name:l.voornaam,last_name:l.achternaam,username:l.email,password:Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2).toUpperCase()+"!1",wefact_klantid:l.code,company_name:l.bedrijf,place:l.stad,zipcode:l.postcode,status:"ACTIVE",tms_personeel:S.tms,unit10_personeel:S.unit10,rstcc_personeel:S.rstcc})}),s=await a.json();if(!a.ok){V(JSON.stringify(s));return}G({id:s.id,first_name:s.first_name,last_name:s.last_name,email:s.email,username:s.username}),y(null),b([]),I("")}catch{V("Netwerkfout")}finally{E(!1)}}},$=(a,s)=>h(i=>i.map(n=>n.id===a?{...n,...s}:n)),ne=(a,s)=>{const i=s.length>0?J.filter(n=>`${n.title} ${n.art_no}`.toLowerCase().includes(s.toLowerCase())).slice(0,8):[];$(a,{query:s,results:i,showResults:i.length>0,productId:null,productTitle:"",artNo:""})},le=(a,s)=>$(a,{productId:s.id,productTitle:s.title,artNo:s.art_no,price:parseFloat(s.price).toFixed(2),query:s.title,results:[],showResults:!1}),t=async()=>{if(F.trim()){D(!0),T("");try{const a=await fetch(`${x}/api/ai-generate-order-lines/`,{method:"POST",headers:c,body:JSON.stringify({prompt:F,products:J.slice(0,40).map(n=>({art_no:n.art_no,title:n.title,price:n.price}))})}),s=await a.json();if(!a.ok){T(s.error||"AI fout");return}const i=(s.lines||[]).map(n=>({...f(),query:n.description||"",description:n.description||"",quantity:Math.max(1,parseInt(n.quantity)||1),price:parseFloat(n.price_incl_btw||0).toFixed(2)}));i.length>0&&(h(i),X("lines"))}catch{T("Netwerkfout")}finally{D(!1)}}},o=async()=>{if(!p){H("Selecteer een klant.");return}const a=C.filter(s=>s.productId||(s.query||s.description).trim());se(!0),H("");try{const s=await fetch(`${x}/api/orders/`,{method:"POST",headers:c,body:JSON.stringify({user:p.id,status:m==="offerte"?"OFFERTE":"PENDING",is_private:q})});if(!s.ok){const n=await s.json();H(JSON.stringify(n));return}const i=await s.json();for(const n of a){const v={quantity:n.quantity,price_at_order:parseFloat(n.price||"0").toFixed(2),btw_tarief:"21"};n.productId?v.product=n.productId:v.custom_description=(n.query||n.description).trim(),await fetch(`${x}/api/orders/${i.id}/lines/`,{method:"POST",headers:c,body:JSON.stringify(v)})}U(i.id)}finally{se(!1)}},d=ie||L.length>0||l;return e.jsx(B.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:a=>{a.target===a.currentTarget&&A()},children:e.jsxs(B.div,{initial:{opacity:0,y:32,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:32,scale:.97},className:"bg-surface-container rounded-[2rem] border border-outline-variant/20 w-full max-w-2xl max-h-[92vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-8 pt-8 pb-5 space-y-5 border-b border-outline-variant/10 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 mb-1",children:"Orders"}),e.jsx("h3",{className:"text-2xl font-black tracking-tight",children:"Nieuwe bestelling"})]}),e.jsx("button",{onClick:A,className:"w-9 h-9 rounded-xl bg-surface-container-high flex items-center justify-center hover:bg-surface-container-highest transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"close"})})]}),e.jsxs("div",{className:"flex gap-3 items-center",children:[e.jsx("div",{className:"flex bg-surface-container-high rounded-2xl p-1 border border-outline-variant/10 flex-shrink-0",children:["order","offerte"].map(a=>e.jsx("button",{type:"button",onClick:()=>Q(a),className:`px-5 py-2 rounded-xl text-[10px] font-black uppercase tracking-widest transition-all ${m===a?"bg-primary text-on-primary shadow-md":"text-on-surface-variant/60 hover:text-on-surface"}`,children:a==="order"?"Order":"Offerte"},a))}),m==="offerte"&&e.jsxs("div",{className:"flex items-center gap-3 bg-white/3 border border-white/8 rounded-2xl px-4 py-2 flex-1",children:[e.jsx("span",{className:"text-[10px] font-black flex-1",children:"Verborgen voor klant"}),e.jsx("button",{type:"button",onClick:()=>Y(a=>!a),className:`relative w-10 h-5 rounded-full transition-all duration-300 flex-shrink-0 ${q?"bg-primary":"bg-white/15"}`,children:e.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-all duration-300 ${q?"left-5":"left-0.5"}`})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"Klant"}),p?e.jsxs("div",{className:"flex items-center justify-between bg-primary/10 border border-primary/20 rounded-xl px-4 py-2.5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-black",children:[p.first_name," ",p.last_name]}),e.jsx("div",{className:"text-[11px] opacity-60",children:p.email})]}),e.jsx("button",{onClick:()=>{G(null),y(null),b([])},className:"text-on-surface-variant/50 hover:text-on-surface",children:e.jsx("span",{className:"material-symbols-outlined text-base",children:"close"})})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:u,onChange:a=>{I(a.target.value),y(null)},placeholder:"Zoek op naam of e-mail...",autoFocus:!0,className:"w-full bg-black/20 border border-outline-variant/20 rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:border-primary/50"}),g.length>0&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-surface-container-high border border-outline-variant/20 rounded-2xl overflow-hidden shadow-2xl z-10",children:g.map(a=>e.jsxs("button",{type:"button",onClick:()=>{G(a),I(""),b([])},className:"w-full text-left px-4 py-2.5 hover:bg-primary/10 transition-colors border-b border-outline-variant/10 last:border-0",children:[e.jsxs("div",{className:"text-sm font-bold",children:[a.first_name," ",a.last_name]}),e.jsx("div",{className:"text-[11px] opacity-50",children:a.email})]},a.id))})]}),d&&e.jsxs("div",{className:"bg-surface-container-high border border-outline-variant/15 rounded-2xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"WeFact"}),te&&e.jsx("div",{className:"w-3.5 h-3.5 border-2 border-primary/30 border-t-primary rounded-full animate-spin"})]}),ae&&e.jsx("p",{className:"text-[10px] text-on-surface-variant/50 italic",children:ae}),L.length>0&&!l&&e.jsx("div",{className:"space-y-1",children:L.slice(0,5).map(a=>e.jsx("button",{type:"button",onClick:()=>y(a),className:"w-full text-left px-3 py-2 rounded-xl hover:bg-primary/10 transition-colors border border-outline-variant/10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold",children:a.naam||a.bedrijf}),e.jsxs("div",{className:"text-[10px] opacity-50",children:[a.email,a.bedrijf&&a.naam?` · ${a.bedrijf}
1`:"",a.postcode||a.stad?` · ${[a.postcode,a.stad].filter(Boolean).join(" ")}`:""]})]}),e.jsx("span",{className:"text-[9px] font-mono text-on-surface-variant/30",children:a.code})]})},a.code))}),l&&!p&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black",children:l.naam||l.bedrijf}),l.naam&&l.bedrijf&&e.jsx("div",{className:"text-[10px] opacity-60",children:l.bedrijf}),e.jsxs("div",{className:"text-[10px] opacity-50",children:[l.email," · ",[l.postcode,l.stad].filter(Boolean).join(" ")||l.code]})]}),e.jsx("button",{onClick:()=>y(null),className:"text-on-surface-variant/40",children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"close"})})]}),e.jsx("div",{className:"flex gap-1.5",children:["tms","unit10","rstcc"].map(a=>e.jsx("button",{type:"button",onClick:()=>W(s=>({...s,[a]:!s[a]})),className:`flex-1 py-1.5 rounded-xl text-[9px] font-black uppercase tracking-widest border transition-all ${S[a]?"bg-primary/10 border-primary/20 text-primary":"border-outline-variant/20 text-on-surface-variant/50"}`,children:a.toUpperCase()},a))}),z&&e.jsx("p",{className:"text-red-400 text-[10px]",children:z}),e.jsx("button",{onClick:R,disabled:_,className:"w-full flex items-center justify-center gap-2 py-2 rounded-xl bg-primary text-on-primary text-[10px] font-black uppercase tracking-widest disabled:opacity-40",children:_?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-3 h-3 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Aanmaken..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"person_add"}),"Aanmaken"]})})]})]})]})]}),p&&e.jsx("div",{className:"flex bg-surface-container-high rounded-2xl p-1 border border-outline-variant/10",children:[["lines","format_list_bulleted","Regels"],["ai","auto_awesome","AI genereren"]].map(([a,s,i])=>e.jsxs("button",{type:"button",onClick:()=>X(a),className:`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest transition-all ${N===a?"bg-primary text-on-primary shadow-md":"text-on-surface-variant/60 hover:text-on-surface"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:s}),i]},a))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-8 py-5 space-y-4",children:[!p&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-on-surface-variant/30 gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-4xl",children:"person_search"}),e.jsx("span",{className:"text-[11px] font-black uppercase tracking-widest",children:"Zoek eerst een klant"})]}),p&&N==="lines"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_60px_100px_36px] gap-2 px-1",children:[e.jsx("span",{className:"text-[8px] font-black uppercase tracking-widest opacity-40",children:"Product / omschrijving"}),e.jsx("span",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 text-center",children:"Qty"}),e.jsx("span",{className:"text-[8px] font-black uppercase tracking-widest opacity-40 text-right",children:"Prijs incl."}),e.jsx("span",{})]}),C.map((a,s)=>e.jsx("div",{className:"relative",children:e.jsxs("div",{className:"grid grid-cols-[1fr_60px_100px_36px] gap-2 items-start",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:a.query,onChange:i=>ne(a.id,i.target.value),onBlur:()=>setTimeout(()=>$(a.id,{showResults:!1}),150),placeholder:`Regel ${s+1}…`,className:"w-full bg-black/20 border border-outline-variant/20 rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:border-primary/50"}),a.productId&&e.jsx("div",{className:"text-[9px] text-primary/70 px-3 pt-0.5 truncate",children:a.artNo}),a.showResults&&a.results.length>0&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-surface-container-high border border-outline-variant/20 rounded-2xl overflow-hidden shadow-2xl z-20",children:a.results.map(i=>e.jsxs("button",{type:"button",onMouseDown:()=>le(a.id,i),className:"w-full text-left px-3 py-2.5 hover:bg-primary/10 transition-colors border-b border-outline-variant/10 last:border-0",children:[e.jsx("div",{className:"text-sm font-bold",children:i.title}),e.jsxs("div",{className:"text-[10px] opacity-50",children:[i.art_no," · €",parseFloat(i.price).toFixed(2)]})]},i.id))})]}),e.jsx("input",{type:"number",min:1,value:a.quantity,onChange:i=>$(a.id,{quantity:Math.max(1,parseInt(i.target.value)||1)}),className:"bg-black/20 border border-outline-variant/20 rounded-xl px-2 py-2.5 text-sm text-center focus:outline-none focus:border-primary/50 w-full"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-sm text-on-surface-variant/40",children:"€"}
1),e.jsx("input",{type:"number",min:0,step:.01,value:a.price,onChange:i=>$(a.id,{price:i.target.value}),placeholder:"0.00",className:"w-full bg-black/20 border border-outline-variant/20 rounded-xl pl-6 pr-2 py-2.5 text-sm text-right focus:outline-none focus:border-primary/50"})]}),e.jsx("button",{type:"button",onClick:()=>h(i=>i.filter(n=>n.id!==a.id)),disabled:C.length===1,className:"w-9 h-10 flex items-center justify-center text-on-surface-variant/30 hover:text-red-400 transition-colors disabled:opacity-20 rounded-xl",children:e.jsx("span",{className:"material-symbols-outlined text-base",children:"delete"})})]})},a.id)),e.jsxs("button",{type:"button",onClick:()=>h(a=>[...a,f()]),className:"w-full flex items-center justify-center gap-2 py-2.5 rounded-xl border border-dashed border-outline-variant/30 text-[10px] font-black uppercase tracking-widest text-on-surface-variant/40 hover:border-primary/40 hover:text-primary/60 transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Regel toevoegen"]})]}),p&&N==="ai"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[9px] font-black uppercase tracking-widest opacity-50",children:"Omschrijf de offerte"}),e.jsx("textarea",{rows:5,value:F,onChange:a=>O(a.target.value),placeholder:"Bijv: Een offerte voor webdesign inclusief 5 pagina's, hosting voor 1 jaar en een logo ontwerp. Budget rond €3000.",className:"w-full bg-black/20 border border-outline-variant/20 rounded-2xl px-4 py-3 text-sm focus:outline-none focus:border-primary/50 resize-none leading-relaxed",autoFocus:!0})]}),xe&&e.jsx("p",{className:"text-red-400 text-[11px] bg-red-500/10 rounded-xl px-3 py-2",children:xe}),e.jsx("button",{type:"button",onClick:t,disabled:P||!F.trim(),className:"w-full flex items-center justify-center gap-2.5 py-3.5 rounded-2xl bg-gradient-to-r from-violet-600 to-primary text-white text-[11px] font-black uppercase tracking-widest hover:opacity-90 transition-all disabled:opacity-40 shadow-lg shadow-violet-500/20",children:P?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"AI genereert regels..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-base",children:"auto_awesome"}),"Genereer orderregels"]})}),e.jsx("p",{className:"text-[10px] text-on-surface-variant/40 text-center",children:"AI genereert regels op basis van je omschrijving. Je kunt ze daarna aanpassen op het tabblad Regels."})]})]}),e.jsxs("div",{className:"px-8 pb-6 pt-4 border-t border-outline-variant/10 flex-shrink-0 space-y-3",children:[re&&e.jsx("p",{className:"text-red-400 text-xs bg-red-500/10 rounded-xl px-4 py-2.5",children:re}),p&&N==="lines"&&e.jsxs("div",{className:"flex justify-end text-[11px] text-on-surface-variant/50",children:["Totaal: ",e.jsxs("span",{className:"font-black text-on-surface ml-1.5",children:["€",C.reduce((a,s)=>a+parseFloat(s.price||"0")*s.quantity,0).toFixed(2)]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:A,className:"flex-1 py-3.5 rounded-xl bg-surface-container-high border border-outline-variant/20 text-[10px] font-black uppercase tracking-widest hover:bg-surface-container-highest transition-all",children:"Annuleer"}),e.jsx("button",{onClick:o,disabled:Z||!p||N==="lines"&&C.filter(a=>a.productId||(a.query||a.description).trim()).length===0,className:"flex-1 flex items-center justify-center gap-2 py-3.5 rounded-xl bg-primary text-on-primary text-[10px] font-black uppercase tracking-widest hover:bg-primary/90 transition-all disabled:opacity-40",children:Z?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Aanmaken..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:m==="offerte"?"description":"add_shopping_cart"}),m==="offerte"?"Offerte aanmaken":"Bestelling aanmaken"]})})]})]})]})})}export{Se 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.