PageSourceSearch

https://swap-box.com/assets/RouteTemplates-CqWncLIq.js

js swap-box.com collected 2026-10-05 22:58:54 UTC 25,068 bytes, 11 lines download raw bytes

1import{ah as ce,E as Z,r as n,s as h,j as e,D as de,o as me,p as ue,q as pe,v as xe,I as z,w as De,B as y,a2 as F,a7 as he,h as Ee,g as Le,aw as Ae}from"./index-CPe-RtOb.js";import{u as Re}from"./useWashingQueueEnabled-0BRQ-pAP.js";import{f as J}from"./formatDate-Nv3Yi38l.js";import{L as S}from"./label-Bv11FUgq.js";import{B as M}from"./badge-DiwtLCWR.js";import{C as ee,b as je,c as ve,a as fe,d as Oe}from"./card-MfW-rXM9.js";import{T as Pe,a as Ie,b as ie,c as ne}from"./tabs-59-XQtVP.js";import{T as _e,a as ge,b as Q,c as T,d as be,e as D}from"./table-0aI2kcCf.js";import{S as ze}from"./switch-D2gruW-6.js";import{S as we,a as ke,b as ye,c as Ne,d as Se}from"./select-BEbqKSAt.js";import{C as qe,a as Ve,b as Be,c as We,d as $e,e as Ge,f as Ke}from"./command-CL_Il3EY.js";import{P as Me,a as Fe,b as Ue}from"./popover-DvICt7tI.js";import{a as He,W as te,n as L,c as Ye,w as Je}from"./routeTemplateUtils-DoJiS3om.js";import{P as Ce}from"./plus-Chks3yxq.js";import{A as Qe,a as Ze}from"./arrow-up-Cm2VIC-D.js";import{T as Xe}from"./trash-2-Bc1yFWzC.js";import{L as et}from"./lock-5xQDTfUH.js";import{R as tt}from"./route-BGVv3kmu.js";import{W as st}from"./wand-sparkles-4-u7w7BC.js";import{P as at}from"./pencil-BRReSao3.js";import{P as rt}from"./power-off-Cwnrdljx.js";import"./format-Bf8w0AYm.js";import"./parseISO-DPcQxUhV.js";import"./index-BdQq_4o_.js";import"./search-CAOX7utX.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const le=ce("GitCompare",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const it=ce("Power",[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]]);let nt=0;const lt=()=>`tmp-${Date.now()}-${nt++}`;function oe(m){return{key:lt(),id:null,location_id:null,location_name_snapshot:"",standard_stop_number:m,expected_delivery_crates:null,expected_pickup_crates:null,notes:null}}function ot({open:m,onOpenChange:w,template:t,locations:q,onSaved:u}){const{toast:p}=Z(),[f,_]=n.useState(!1),[g,i]=n.useState(!1),[A,V]=n.useState(""),[E,W]=n.useState(1),[a,l]=n.useState(""),[x,o]=n.useState(""),[j,C]=n.useState(""),[B,O]=n.useState(""),[s,v]=n.useState(!0),[b,c]=n.useState([]);n.useEffect(()=>{m&&(V((t==null?void 0:t.template_name)??""),W((t==null?void 0:t.weekday)??1),l((t==null?void 0:t.route_label)??""),o((t==null?void 0:t.default_driver_serial)??""),C((t==null?void 0:t.region)??""),O((t==null?void 0:t.description)??""),v((t==null?void 0:t.is_active)??!0),t?(i(!0),(async()=>{const{data:r,error:N}=await h.from("route_template_stops").select("*").eq("template_id",t.id).eq("is_active",!0).order("standard_stop_number",{ascending:!0});N&&p({title:"Kon stops niet laden",description:N.message,variant:"destructive"}),c((r??[]).map(d=>({key:d.id,id:d.id,location_id:d.location_id,location_name_snapshot:d.location_name_snapshot,standard_stop_number:d.standard_stop_number,expected_delivery_crates:d.expected_delivery_crates,expected_pickup_crates:d.expected_pickup_crates,notes:d.notes}))),i(!1)})()):c([oe(1)]))},[m,t,p]);const P=r=>r.map((N,k)=>({...N,standard_stop_number:k+1})),$=()=>c(r=>[...r,oe(r.length+1)]),X=r=>c(N=>P(N.filter(k=>k.key!==r))),U=(r,N)=>{c(k=>{const d=[...k],G=r+N;return G<0||G>=d.length?k:([d[r],d[G]]=[d[G],d[r]],P(d))})},H=(r,N)=>c(k=>k.map(d=>d.key===r?{...d,...N}:d)),R=async()=>{var N;if(!A.trim()){p({title:"Naam verplicht",description:"Geef de template een naam.",variant:"destructive"});return}if(!a.trim()){p({title:"Route label verplicht",variant:"destructive"});return}const r=b.filter(k=>k.location_name_snapshot.trim());if(r.length===0){p({title:"Minimaal één stop nodig",variant:"destructive"});return}_(!0);try{const{data:k}=await h.auth.getUser(),d=((N=k.user)==null?void 0:N.id)??null,G={template_name:A.trim(),weekday:E,route_label:a.trim(),default_driver_serial:x.trim()||null,region:j.trim()||null,description:B.trim()||null,is_active:s};let se=t==null?void 0:t.id;if(t){const{error:I}=await h.from("route_templates").update(G).eq("id",t.id);if(I)throw I;const{error:K}=await h.from("route_template_stops").update({is_active:!1}).eq("template_id",t.id).eq("is_active",!0);if(K)throw K}else{const{data:I,error:K}=await h.from("route_templates").insert({...G,created_by:d}).select("id").single();if(K)throw K;se=I.id}const Te=r.map((I,K)=>{var re;return{template_id:se,location_id:I.location_id,location_name_snapshot:I.location_name_snapshot.trim(),standard_stop_number:K+1,expected_delivery_crates:I.expected_delivery_crates,expected_pickup_crates:I.expected_pickup_crates,notes:((re=I.notes)==null?void 0:re.trim())||null,is_active:!0}}),{error:ae}=await h.from("route_template_stops").insert(Te);if(ae)throw ae;p({title:t?"Template bijgewerkt":"Template aangemaakt"}),u(),w(!1)}catch(k){const d=k instanceof Error?k.message:"Onbekende fout";p({title:"Opslaan mislukt",description:d,variant:"destructive"})}finally{_(!1)}};return e.jsx(de,{open:m,onOpenChange:w,children:e.jsxs(me,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ue,{children:[e.jsx(pe,{children:t?"Template bewerken":"Nieuwe route template"}),e.jsx(xe,{children:"Standaard terugkerende route. Alleen planning/referentie — wordt niet gebruikt om de live route of de washing queue aan te sturen."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Template naam"}),e.jsx(z,{value:A,onChange:r=>V(r.target.value),placeholder:"Bijv. Route Noord"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Week
11dag"}),e.jsxs(we,{value:String(E),onValueChange:r=>W(Number(r)),children:[e.jsx(ke,{children:e.jsx(ye,{})}),e.jsx(Ne,{children:He.map(r=>e.jsx(Se,{value:String(r.value),children:r.label},r.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Route label"}),e.jsx(z,{value:a,onChange:r=>l(r.target.value),placeholder:"driver_serial of routenaam"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Standaard chauffeur (serial, optioneel)"}),e.jsx(z,{value:x,onChange:r=>o(r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Regio (optioneel)"}),e.jsx(z,{value:j,onChange:r=>C(r.target.value)})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-7",children:[e.jsx(ze,{checked:s,onCheckedChange:v,id:"tpl-active"}),e.jsx(S,{htmlFor:"tpl-active",children:"Actief"})]}),e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(S,{children:"Omschrijving (optioneel)"}),e.jsx(De,{value:B,onChange:r=>O(r.target.value),rows:2})]})]}),e.jsxs("div",{className:"space-y-2 mt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"text-base",children:["Stops (",b.length,")"]}),e.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:$,children:[e.jsx(Ce,{className:"h-4 w-4 mr-1"})," Stop toevoegen"]})]}),g?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground py-6 justify-center",children:[e.jsx(F,{className:"h-4 w-4 animate-spin"})," Stops laden…"]}):e.jsx("div",{className:"space-y-3",children:b.map((r,N)=>e.jsx(ct,{index:N,total:b.length,stop:r,locations:q,onMove:U,onRemove:X,onChange:H},r.key))})]}),e.jsxs(he,{children:[e.jsx(y,{variant:"outline",onClick:()=>w(!1),disabled:f,children:"Annuleren"}),e.jsxs(y,{onClick:R,disabled:f,children:[f&&e.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),t?"Wijzigingen opslaan":"Template aanmaken"]})]})]})})}function ct({index:m,total:w,stop:t,locations:q,onMove:u,onRemove:p,onChange:f}){const[_,g]=n.useState(!1);return e.jsxs("div",{className:"rounded-lg border p-3 space-y-3 bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-primary/10 text-primary text-sm font-semibold shrink-0",children:t.standard_stop_number}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs(Me,{open:_,onOpenChange:g,children:[e.jsx(Fe,{asChild:!0,children:e.jsxs(y,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[e.jsx("span",{className:"truncate",children:t.location_name_snapshot||"Locatie zoeken of vrije tekst…"}),e.jsx(qe,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Ue,{className:"w-[--radix-popover-trigger-width] p-0 bg-popover",align:"start",children:e.jsxs(Ve,{children:[e.jsx(Be,{placeholder:"Locatie zoeken…",onValueChange:i=>f(t.key,{location_name_snapshot:i,location_id:null})}),e.jsxs(We,{children:[e.jsx($e,{children:"Geen match. Vrije tekst wordt opgeslagen."}),e.jsx(Ge,{children:q.slice(0,200).map(i=>e.jsxs(Ke,{value:`${i.name} ${i.location_code??""}`,onSelect:()=>{f(t.key,{location_id:i.id,location_name_snapshot:i.name}),g(!1)},children:[e.jsx(Ee,{className:Le("mr-2 h-4 w-4",t.location_id===i.id?"opacity-100":"opacity-0")}),i.name,i.location_code?` · ${i.location_code}`:""]},i.id))})]})]})})]}),!t.location_id&&t.location_name_snapshot&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Vrije tekst (geen gekoppelde locatie-ID)"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(y,{type:"button",variant:"ghost",size:"icon",disabled:m===0,onClick:()=>u(m,-1),children:e.jsx(Qe,{className:"h-4 w-4"})}),e.jsx(y,{type:"button",variant:"ghost",size:"icon",disabled:m===w-1,onClick:()=>u(m,1),children:e.jsx(Ze,{className:"h-4 w-4"})}),e.jsx(y,{type:"button",variant:"ghost",size:"icon",onClick:()=>p(t.key),children:e.jsx(Xe,{className:"h-4 w-4 text-destructive"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{className:"text-xs",children:"Verwachte levering"}),e.jsx(z,{type:"number",value:t.expected_delivery_crates??"",onChange:i=>f(t.key,{expected_delivery_crates:i.target.value===""?null:Number(i.target.value)})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{className:"text-xs",children:"Verwachte ophaal"}),e.jsx(z,{type:"number",value:t.expected_pickup_crates??"",onChange:i=>f(t.key,{expected_pickup_crates:i.target.value===""?null:Number(i.target.value)})})]}),e.jsxs("div",{className:"space-y-1 col-span-2 sm:col-span-1",children:[e.jsx(S,{className:"text-xs",children:"Notitie"}),e.jsx(z,{value:t.notes??"",onChange:i=>f(t.key,{notes:i.target.value})})]})]})]})}const Y={green:{label:"Komt overeen",className:"bg-emerald-100 text-emerald-800 border-emerald-200"},yellow:{label:"Afwijking",className:"bg-amber-100 text-amber-800 border-amber-200"},red:{label:"Probleem",className:"bg-rose-100 text-rose-800 border-rose-200"}},dt=()=>new Date().toISOString().slice(0,10);function mt({templates:m}){const{toast:w}=Z(),[t,q]=n.useState(dt()),[u,p]=n.useState(""),[f,_]=n.useState(!1),[g,i]=n.useState(null),[A,V]=n.useState(null),E=m.filter(a=>a.is_active);n.useEffect(()=>{!u&&E.length>0&&p(E[0].id)},[E,u]);const W=async()=>{const a=m.find(l=>l.id===u);if(!a){w({title:"Kies een template",variant:"destructive"});return}_(!0),i(null),V(null);try{const{data:l,error:x}=await h.from("route_template_stops").select("*").eq("template_id",a.id).eq("is_active",!0);if(x)throw x;const o=l??[],{data:j,error:C}=await h.from("optimoroute_stops").select("id, stop_number, location_name, location_no, driver_serial, driver_name, crates_collected, load_1").eq("route_date",t);if(C)throw C;const B=L(a.route_label),O=L(a.default_driver_serial),s=(j??[]).filter(v=>{const b=L(v.driver_serial),c=L(v.driver_name);return b===B||c===B||O&&(b===O||c===O)});V(s.length),i(Ye(o,s))}catch(l){const x=l instanceof Error?l.message:"Onbekende fout";w({title:"Vergelijken mislukt",description:x,variant:"destructive"})}finally{_(!1)}};return e.jsxs(ee,{children:[e.jsx(je,{children:e.jsxs(ve,{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-5 w-5"})," Werkelijke route vs template"]})}),e.jsxs(fe,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 items-end",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Datum"}),e.jsx(z,{type:"date",value:t,onChange:a=>q(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Template"}),e.jsxs(we,{value:u,onValueChange:p,children:[e.jsx(ke,{children:e.jsx(ye,{placeholder:"Kies template"})}),e.jsx(Ne,{children:E.map(a=>e.jsxs(Se,{value:a.id,children:[a.template_name," · ",te[a.weekday]," · ",a.route_label]},a.id))})]})]}),e.jsxs(y,{onClick:W,disabled:f||!u,children:[f?e.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(le,{className:"h-4 w-4 mr-2"}),"Vergelijk"]})]}),g&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(M,{variant:"outline",className:Y[g.summary.overall].className,children:["Totaal: ",Y[g.summary.overall].label]}),e.jsxs(M,{variant:"outline",className:"bg-emerald-50 text-emerald-700 border-emerald-200",children:[g.summary.matched," overeenkomend"]}),e.jsxs(M,{variant:"outline",className:"bg-amber-50 text-amber-700 border-amber-200",children:[g.summary.warnings," afwijkingen"]}),e.jsxs(M,{variant:"outline",className:"bg-rose-50 text-rose-700 border-rose-200",children:[g.summary.problems," problemen"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[A??0," werkelijke stops gevonden voor deze datum/route"]})]}),g.rows.length===0?e.jsx("p",{className:"text-muted-foreground text-sm py-4",children:"Geen stops om te vergelijken. Controleer of er voor deze datum een geïmporteerde route met dit label bestaat."}):e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs(_e,{children:[e.jsx(ge,{children:e.jsxs(Q,{children:[e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Locatie"}),e.jsx(T,{className:"text-center",children:"Std stop"}),e.jsx(T,{className:"text-center",children:"Werkelijk stop"}),e.jsx(T,{className:"text-center",children:"Levering (v/w)"}),e.jsx(T,{className:"text-center",children:"Ophaal (v/w)"}),e.jsx(T,{children:"Toelichting"})]})}),e.jsx(be,{children:g.rows.map(a=>e.jsxs(Q,{children:[e.jsx(D,{children:e.jsx(M,{variant:"outline",className:Y[a.status].className,children:Y[a.status].label})}),e.jsxs(D,{className:"font-medium",children:[a.locationName,a.needsLocationId&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(geen locatie-ID)"})]}),e.jsx(D,{className:"text-center",children:a.templateStopNumber??"—"}),e.jsx(D,{className:"text-center",children:a.actualStopNumber??"—"}),e.jsxs(D,{className:"text-center",children:[a.expectedDeliveryCrates??"—"," / ",a.actualDeliveryCrates??"—"]}
11),e.jsxs(D,{className:"text-center",children:[a.expectedPickupCrates??"—"," / ",a.actualPickupCrates??"—"]}),e.jsx(D,{className:"text-sm text-muted-foreground",children:a.reasons.join("; ")})]},a.key))})]})})]})]})]})}function qt(){const{toast:m}=Z(),{enabled:w,loading:t}=Re(),[q,u]=n.useState(!0),[p,f]=n.useState([]),[_,g]=n.useState({}),[i,A]=n.useState([]),[V,E]=n.useState(!1),[W,a]=n.useState(null),[l,x]=n.useState(!1),o=n.useCallback(async()=>{u(!0);try{const[{data:s,error:v},{data:b,error:c}]=await Promise.all([h.from("route_templates").select("*").order("weekday").order("route_label"),h.from("route_template_stops").select("template_id").eq("is_active",!0)]);if(v)throw v;if(c)throw c;f(s??[]);const P={};for(const $ of b??[])P[$.template_id]=(P[$.template_id]??0)+1;g(P)}catch(s){const v=s instanceof Error?s.message:"Onbekende fout";m({title:"Laden mislukt",description:v,variant:"destructive"})}finally{u(!1)}},[m]);n.useEffect(()=>{w&&(o(),h.from("locations").select("id, name, location_code").order("name").then(({data:s})=>A(s??[])))},[w,o]);const j=()=>{a(null),E(!0)},C=s=>{a(s),E(!0)},B=async s=>{const{error:v}=await h.from("route_templates").update({is_active:!s.is_active}).eq("id",s.id);if(v){m({title:"Bijwerken mislukt",description:v.message,variant:"destructive"});return}m({title:s.is_active?"Template gedeactiveerd":"Template geactiveerd"}),o()},O=async s=>{var v;try{const{data:b}=await h.auth.getUser(),c=((v=b.user)==null?void 0:v.id)??null,{data:P,error:$}=await h.from("route_template_stops").select("*").eq("template_id",s.id).eq("is_active",!0);if($)throw $;const{data:X,error:U}=await h.from("route_templates").insert({template_name:`${s.template_name} (kopie)`,weekday:s.weekday,route_label:`${s.route_label}-kopie`,default_driver_serial:s.default_driver_serial,region:s.region,description:s.description,is_active:!1,created_by:c}).select("id").single();if(U)throw U;const H=(P??[]).map(R=>({template_id:X.id,location_id:R.location_id,location_name_snapshot:R.location_name_snapshot,standard_stop_number:R.standard_stop_number,expected_delivery_crates:R.expected_delivery_crates,expected_pickup_crates:R.expected_pickup_crates,notes:R.notes,is_active:!0}));if(H.length){const{error:R}=await h.from("route_template_stops").insert(H);if(R)throw R}m({title:"Template gedupliceerd",description:"Kopie is inactief aangemaakt."}),o()}catch(b){const c=b instanceof Error?b.message:"Onbekende fout";m({title:"Dupliceren mislukt",description:c,variant:"destructive"})}};return t?e.jsx("div",{className:"min-h-[60vh] flex items-center justify-center",children:e.jsx(F,{className:"h-8 w-8 animate-spin text-primary"})}):w?e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(tt,{className:"h-6 w-6"})," Route Templates"]}),e.jsx("p",{className:"text-muted-foreground mt-1 max-w-2xl",children:"Standaard terugkerende routes per weekdag en route/chauffeur label. Planning & referentie — niet gekoppeld als bron voor de live route of washing queue."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{variant:"outline",onClick:()=>x(!0),children:[e.jsx(st,{className:"h-4 w-4 mr-2"})," Vanuit werkelijke route"]}),e.jsxs(y,{onClick:j,children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"})," Nieuwe template"]})]})]}),e.jsxs(Pe,{defaultValue:"list",children:[e.jsxs(Ie,{children:[e.jsx(ie,{value:"list",children:"Templates"}),e.jsx(ie,{value:"compare",children:"Vergelijken"})]}),e.jsx(ne,{value:"list",className:"mt-4",children:e.jsx(ee,{children:e.jsx(fe,{className:"pt-6",children:q?e.jsxs("div",{className:"flex items-center gap-2 justify-center py-10 text-muted-foreground",children:[e.jsx(F,{className:"h-5 w-5 animate-spin"})," Templates laden…"]}):p.length===0?e.jsx("p",{className:"text-muted-foreground py-10 text-center",children:"Nog geen route templates. Maak er een aan of genereer er een vanuit een werkelijke route."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(_e,{children:[e.jsx(ge,{children:e.jsxs(Q,{children:[e.jsx(T,{children:"Naam"}
11),e.jsx(T,{children:"Weekdag"}),e.jsx(T,{children:"Route label"}),e.jsx(T,{className:"text-center",children:"Stops"}),e.jsx(T,{className:"text-center",children:"Status"}),e.jsx(T,{children:"Bijgewerkt"}),e.jsx(T,{className:"text-right",children:"Acties"})]})}),e.jsx(be,{children:p.map(s=>e.jsxs(Q,{children:[e.jsx(D,{className:"font-medium",children:s.template_name}),e.jsx(D,{children:te[s.weekday]}),e.jsx(D,{children:s.route_label}),e.jsx(D,{className:"text-center",children:_[s.id]??0}),e.jsx(D,{className:"text-center",children:s.is_active?e.jsx(M,{variant:"outline",className:"bg-emerald-50 text-emerald-700 border-emerald-200",children:"Actief"}):e.jsx(M,{variant:"outline",className:"text-muted-foreground",children:"Inactief"})}),e.jsx(D,{children:J(s.updated_at)}),e.jsx(D,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(y,{variant:"ghost",size:"icon",title:"Bewerken",onClick:()=>C(s),children:e.jsx(at,{className:"h-4 w-4"})}),e.jsx(y,{variant:"ghost",size:"icon",title:"Dupliceren",onClick:()=>O(s),children:e.jsx(Ae,{className:"h-4 w-4"})}),e.jsx(y,{variant:"ghost",size:"icon",title:s.is_active?"Deactiveren":"Activeren",onClick:()=>B(s),children:s.is_active?e.jsx(rt,{className:"h-4 w-4 text-destructive"}):e.jsx(it,{className:"h-4 w-4 text-emerald-600"})})]})})]},s.id))})]})})})})}),e.jsx(ne,{value:"compare",className:"mt-4",children:e.jsx(mt,{templates:p})})]}),e.jsx(ot,{open:V,onOpenChange:E,template:W,locations:i,onSaved:o}),e.jsx(ut,{open:l,onOpenChange:x,locations:i,onCreated:o})]}):e.jsx("div",{className:"p-6 max-w-2xl mx-auto",children:e.jsx(ee,{children:e.jsxs(je,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-3 h-12 w-12 rounded-full bg-muted flex items-center justify-center",children:e.jsx(et,{className:"h-6 w-6 text-muted-foreground"})}),e.jsx(ve,{children:"Route Templates uitgeschakeld"}),e.jsx(Oe,{children:"Deze module hoort bij de washing preview (shadow mode) en is momenteel uitgeschakeld via de feature-flag. Bestaande templates blijven bewaard."})]})})})}function ut({open:m,onOpenChange:w,locations:t,onCreated:q}){const{toast:u}=Z(),[p,f]=n.useState(new Date().toISOString().slice(0,10)),[_,g]=n.useState(""),[i,A]=n.useState(!1),V=n.useMemo(()=>{const l=new Map;for(const x of t)l.set(L(x.name),x.id);return l},[t]),E=async()=>{const{data:l,error:x}=await h.from("optimoroute_stops").select("id, stop_number, location_name, location_no, driver_serial, driver_name, crates_collected, load_1").eq("route_date",p);if(x)throw x;const o=L(_);return(l??[]).filter(j=>L(j.driver_serial)===o||L(j.driver_name)===o).sort((j,C)=>(j.stop_number??1e9)-(C.stop_number??1e9))},W=async()=>{if(!_.trim()){u({title:"Vul eerst een route label in",variant:"destructive"});return}const l=L(_),{data:x,error:o}=await h.from("optimoroute_stops").select("route_date, driver_serial, driver_name").order("route_date",{ascending:!1}).limit(1e3);if(o){u({title:"Zoeken mislukt",description:o.message,variant:"destructive"});return}const j=(x??[]).find(C=>L(C.driver_serial)===l||L(C.driver_name)===l);if(!j){u({title:"Geen route gevonden voor dit label",variant:"destructive"});return}f(j.route_date),u({title:"Laatste import gevonden",description:`Datum gezet op ${J(j.route_date)}`})},a=async()=>{var l,x;if(!_.trim()){u({title:"Route label verplicht",variant:"destructive"});return}A(!0);try{const o=await E();if(o.length===0){u({title:"Geen stops gevonden",description:"Geen geïmporteerde stops voor deze datum/label.",variant:"destructive"}),A(!1);return}const j=Je(p)??1,{data:C}=await h.auth.getUser(),B=((l=C.user)==null?void 0:l.id)??null,{data:O,error:s}=await h.from("route_templates").insert({template_name:`${_.trim()} — ${te[j]} (uit ${J(p)})`,weekday:j,route_label:_.trim(),default_driver_serial:((x=o.find(c=>c.driver_serial))==null?void 0:x.driver_serial)??null,region:null,description:`Aangemaakt uit werkelijke route van ${J(p)}`,is_active:!1,created_by:B}).select("id").single();if(s)throw s;const v=o.map((c,P)=>({template_id:O.id,location_id:V.get(L(c.location_name))??null,location_name_snapshot:c.location_name||"Onbekende locatie",standard_stop_number:c.stop_number??P+1,expected_delivery_crates:c.load_1??null,expected_pickup_crates:c.crates_collected??null,notes:null,is_active:!0})),{error:b}=await h.from("route_template_stops").insert(v);if(b)throw b;u({title:"Template aangemaakt",description:`${v.length} stops uit werkelijke route (inactief).`}),q(),w(!1)}catch(o){const j=o instanceof Error?o.message:"Onbekende fout";u({title:"Aanmaken mislukt",description:j,variant:"destructive"})}finally{A(!1)}};return e.jsx(de,{open:m,onOpenChange:w,children:e.jsxs(me,{children:[e.jsxs(ue,{children:[e.jsx(pe,{children:"Template vanuit werkelijke route"}),e.jsx(xe,{children:"Leest de geïmporteerde OptimoRoute-stops voor de gekozen datum + route/chauffeur en maakt daar een nieuwe (inactieve) template van. Wijzigt geen routedata."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Route label (driver_serial of chauffeursnaam)"}
11),e.jsx(z,{value:_,onChange:l=>g(l.target.value),placeholder:"bijv. 12345 of Jan"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Datum"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(z,{type:"date",value:p,onChange:l=>f(l.target.value)}),e.jsx(y,{type:"button",variant:"outline",onClick:W,children:"Laatste import"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Weekdag wordt afgeleid uit de datum."})]})]}),e.jsxs(he,{children:[e.jsx(y,{variant:"outline",onClick:()=>w(!1),disabled:i,children:"Annuleren"}),e.jsxs(y,{onClick:a,disabled:i,children:[i&&e.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),"Template aanmaken"]})]})]})})}export{qt 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.