1import{e as V,g as A,r as s,j as e,t as h}from"./index-BSeo_c75.js";import{u as w}from"./useMutation-Dpm_n2i6.js";import{S as M}from"./SafeDialog-B8vdN2zy.js";import{l as K,a as P}from"./CountryIsoSelect-L3RrLy1d.js";import{M as Z}from"./MoneyDisplay-DdE9uC3b.js";import{d as R,A as F,e as E,a as q,h as i,b as O,i as D,f as I}from"./kit-DirKoajS.js";import{c as Q}from"./utils-BQHNewu7.js";import{u as G,d as W,a as B,b as U,e as L,l as $}from"./shop-shipping.functions-BA912yhn.js";import"./dialog-D21yCKqj.js";import"./index-YbPNVSwf.js";import"./index-DaSGHnCu.js";import"./index-DVMAVJAD.js";import"./index-CYIHdRCU.js";import"./index-ButSyumc.js";import"./index-ButzQiUh.js";function me(){const a=V(),n=A({queryKey:["admin","shop","zones"],queryFn:()=>L()}),[r,b]=s.useState(null),[m,d]=s.useState(null),[f,x]=s.useState(!1),[p,c]=s.useState(null),[g,u]=s.useState(null),[o,y]=s.useState(!1),[v,j]=s.useState(null);s.useEffect(()=>{!r&&n.data&&n.data.length>0&&b(n.data[0].id)},[n.data,r]);const N=A({queryKey:["admin","shop","methods",r],queryFn:()=>$({data:{zoneId:r}}),enabled:!!r}),k=w({mutationFn:t=>G({data:t}),onSuccess:()=>{a.invalidateQueries({queryKey:["admin","shop","zones"]}),h.success("Zone opgeslagen"),d(null),x(!1)},onError:t=>h.error(t.message)}),S=w({mutationFn:t=>W({data:{id:t}}),onSuccess:()=>{a.invalidateQueries({queryKey:["admin","shop","zones"]}),h.success("Zone verwijderd"),c(null),b(null)},onError:t=>h.error(t.message)}),C=w({mutationFn:t=>B({data:t}),onSuccess:()=>{a.invalidateQueries({queryKey:["admin","shop","methods",r]}),h.success("Methode opgeslagen"),u(null),y(!1)},onError:t=>h.error(t.message)}),_=w({mutationFn:t=>U({data:{id:t}}),onSuccess:()=>{a.invalidateQueries({queryKey:["admin","shop","methods",r]}),h.success("Methode verwijderd"),j(null)},onError:t=>h.error(t.message)}),l=n.data?.find(t=>t.id===r)??null;return e.jsx(R,{title:"Verzending",description:"Beheer verzendzones en de bijhorende verzendmethodes.",children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[300px_minmax(0,1fr)]",children:[e.jsx(F,{title:"Zones",bodyClassName:"p-3",actions:e.jsx("button",{type:"button",className:"rounded-full bg-brand px-3 py-1.5 text-xs font-semibold text-surface hover:opacity-90",onClick:()=>x(!0),children:"Nieuw"}),children:e.jsxs("ul",{className:"space-y-1",children:[(n.data??[]).map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>b(t.id),className:Q("flex w-full items-center justify-between rounded-xl px-3 py-2 text-left text-sm transition",r===t.id?"bg-surface/60 font-semibold text-ink":"text-ink/70 hover:bg-surface/40"),children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-ink/50",children:t.country_codes.length})]})},t.id)),n.data&&n.data.length===0?e.jsx("li",{children:e.jsx(E,{title:"Nog geen zones",description:"Maak een zone aan om verzendmethodes te beheren."})}):null]})}),e.jsx("div",{className:"space-y-4",children:l?e.jsxs(e.Fragment,{children:[e.jsx(F,{title:l.name,description:l.country_codes.map(t=>K(t)).join(", ")||"Geen landen",actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"rounded-full border border-ink/15 px-3 py-1.5 text-xs font-medium text-ink hover:bg-surface/40",onClick:()=>d(l),children:"Zone bewerken"}),e.jsx("button",{type:"button",className:"rounded-full border border-brand/30 px-3 py-1.5 text-xs font-medium text-brand hover:bg-brand/10",onClick:()=>c(l),children:"Verwijderen"})]}),children:e.jsx(q,{tone:l.is_active?"success":"neutral",children:l.is_active?"Actief":"Inactief"})}),e.jsx(F,{title:"Methodes",bodyClassName:"p-0",actions:e.jsx("button",{type:"button",className:"rounded-full bg-brand px-3 py-1.5 text-xs font-semibold text-surface hover:opacity-90",onClick:()=>y(!0),children:"Methode toevoegen"}),children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-surface/50 text-xs uppercase tracking-wide text-ink/55",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2.5 text-left",children:"Naam"}),e.jsx("th",{className:"px-4 py-2.5 text-left",children:"Vervoerder"}),e.jsx("th",{className:"px-4 py-2.5 text-right",children:"Prijs"}),e.jsx("th",{className:"px-4 py-2.5 text-right",children:"Gratis vanaf"}),e.jsx("th",{className:"px-4 py-2.5 text-center",children:"Actief"}),e.jsx("th",{className:"px-4 py-2.5"})]})}),e.jsxs("tbody",{children:[(N.data??[]).map(t=>e.jsxs("tr",{className:"border-t border-ink/8 hover:bg-surface/30",children:[e.jsx("td",{className:"px-4 py-2.5 text-ink",children:t.name}),e.jsx("td",{className:"px-4 py-2.5 text-ink/70",children:t.carrier??"-"}),e.jsx("td",{className:"px-4 py-2.5 text-right text-ink",children:e.jsx(Z,{amountCents:t.base_price_cents,currency:"EUR"})}),e.jsx("td",{className:"px-4 py-2.5 text-right text-ink/70",children:t.free_from_cents!==null&&t.free_from_cents!==void 0?e.jsx(Z,{amountCents:t.free_from_cents,currency:"EUR"}):"-"}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx(q,{tone:t.is_active?"success":"neutral",children:t.is_active?"Ja":"Nee"})}),e.jsxs("td",{className:"px-4 py-2.5 text-right",children:[e.jsx("button",{type:"button",className:"mr-2 rounded-full border border-ink/15 px-2.5 py-1 text-xs font-medium text-ink hover:bg-surface/40",onClick:()=>u(t),children:"Bewerken"}),e.jsx("button",{type:"button",className:"rounded-full border border-brand/30 px-2.5 py-1 text-xs font-medium text-brand hover:bg-brand/10",onClick:()=>j(t),children:"Verwijder"})]})]},t.id)),N.data&&N.data.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8",children:e.jsx(E,{title:"Nog geen methodes",description:"Voeg een verzendmethode toe voor deze zone."})})}):null]})]})})})]}):e.jsx(E,{title:"Geen zone geselecteerd",description:"Kies of maak een zone om methodes te beheren."})}),f||m?e.jsx(J,{initial:m,onClose:()=>{x(!1),d(null)},onSave:t=>k.mutate(t),busy:k.isPending}):null,p?e.jsx(M,{open:!0,onOpenChange:t=>!t&&c(null),title:"Zone verwijderen",description:`Weet je zeker dat je ${p.name}
1 wil verwijderen? Methodes moeten eerst weg.`,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>c(null),className:"rounded-full border border-ink/15 px-3.5 py-1.5 text-xs font-medium text-ink hover:bg-surface/40",children:"Annuleer"}),e.jsx("button",{type:"button",onClick:()=>S.mutate(p.id),className:"rounded-full bg-brand px-3.5 py-1.5 text-xs font-semibold text-surface disabled:opacity-40",disabled:S.isPending,children:"Verwijder"})]}),children:e.jsx("p",{className:"text-sm text-ink/60",children:"Deze actie is definitief."})}):null,(o||g)&&r?e.jsx(T,{zoneId:r,initial:g,onClose:()=>{y(!1),u(null)},onSave:t=>C.mutate(t),busy:C.isPending}):null,v?e.jsx(M,{open:!0,onOpenChange:t=>!t&&j(null),title:"Methode verwijderen",description:`${v.name} verwijderen?`,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>j(null),className:"rounded-full border border-ink/15 px-3.5 py-1.5 text-xs font-medium text-ink hover:bg-surface/40",children:"Annuleer"}),e.jsx("button",{type:"button",onClick:()=>_.mutate(v.id),className:"rounded-full bg-brand px-3.5 py-1.5 text-xs font-semibold text-surface disabled:opacity-40",disabled:_.isPending,children:"Verwijder"})]}),children:e.jsx("p",{className:"text-sm text-ink/60",children:"Deze actie is definitief."})}):null]})})}function J({initial:a,onClose:n,onSave:r,busy:b}){const[m,d]=s.useState(a?.name??""),[f,x]=s.useState(a?.country_codes??[]),[p,c]=s.useState(a?.sort_order??0),[g,u]=s.useState(a?.is_active??!0);return e.jsx(M,{open:!0,onOpenChange:o=>!o&&n(),title:a?"Zone bewerken":"Nieuwe zone",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-ink/15 px-3.5 py-1.5 text-xs font-medium text-ink hover:bg-surface/40",children:"Annuleer"}),e.jsx("button",{type:"button",onClick:()=>r({id:a?.id,name:m.trim(),country_codes:f,sort_order:p,is_active:g}),disabled:b||!m.trim()||f.length===0,className:"rounded-full bg-brand px-3.5 py-1.5 text-xs font-semibold text-surface disabled:opacity-40",children:"Opslaan"})]}),children:e.jsxs("div",{className:Q("space-y-4",I),children:[e.jsx(i,{label:"Naam",required:!0,children:e.jsx("input",{type:"text",value:m,onChange:o=>d(o.target.value),className:"w-full"})}),e.jsx(i,{label:"Landen (ISO-2)",required:!0,children:e.jsx(P,{value:f,onChange:x})}),e.jsxs(O,{columns:2,children:[e.jsx(i,{label:"Sortering",children:e.jsx("input",{type:"number",value:p,onChange:o=>c(parseInt(o.target.value||"0",10)),className:"w-full"})}),e.jsx(D,{label:"Actief",control:e.jsx("input",{type:"checkbox",checked:g,onChange:o=>u(o.target.checked),className:"h-4 w-4 accent-brand"})})]})]})})}function T({zoneId:a,initial:n,onClose:r,onSave:b,busy:m}){const[d,f]=s.useState(n?.name??""),[x,p]=s.useState(n?.carrier??""),[c,g]=s.useState((n?.base_price_cents??0)/100),[u,o]=s.useState(n?.free_from_cents!==null&&n?.free_from_cents!==void 0?String(n.free_from_cents/100):""),[y,v]=s.useState(n?.min_weight_grams?.toString()??""),[j,N]=s.useState(n?.max_weight_grams?.toString()??""),[k,S]=s.useState(n?.sort_order??0),[C,_]=s.useState(n?.is_active??!0),l=t=>{const z=parseInt(t,10);return!Number.isFinite(z)||z<0?null:z};return e.jsx(M,{open:!0,onOpenChange:t=>!t&&r(),title:n?"Methode bewerken":"Nieuwe methode",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:r,className:"rounded-full border border-ink/15 px-3.5 py-1.5 text-xs font-medium text-ink hover:bg-surface/40",children:"Annuleer"}),e.jsx("button",{type:"button",onClick:()=>b({id:n?.id,zone_id:a,name:d.trim(),carrier:x.trim()||null,base_price_cents:Math.max(0,Math.round(c*100)),free_from_cents:u.trim()===""?null:Math.round(parseFloat(u)*100),min_weight_grams:l(y),max_weight_grams:l(j),sort_order:k,is_active:C}),disabled:m||!d.trim(),className:"rounded-full bg-brand px-3.5 py-1.5 text-xs font-semibold text-surface disabled:opacity-40",children:"Opslaan"})]}),children:e.jsxs(O,{columns:2,className:I,children:[e.jsx(i,{label:"Naam",required:!0,children:e.jsx("input",{type:"text",value:d,onChange:t=>f(t.target.value),className:"w-full"})}),e.jsx(i,{label:"Vervoerder",children:e.jsx("input",{type:"text",value:x,onChange:t=>p(t.target.value),className:"w-full"})}),e.jsx(i,{label:"Basisprijs (EUR)",children:e.jsx("input",{type:"number",step:"0.01",min:"0",value:c,onChange:t=>g(parseFloat(t.target.value||"0")),className:"w-full"})}),e.jsx(i,{label:"Gratis vanaf (EUR)",hint:"Laat leeg om nooit gratis te verzenden.",children:e.jsx("input",{type:"number",step:"0.01",min:"0",value:u,onChange:t=>o(t.target.value),className:"w-full"})}),e.jsx(i,{label:"Min gewicht (g)",children:e.jsx("input",{type:"number",min:"0",value:y,onChange:t=>v(t.target.value),className:"w-full"})}),e.jsx(i,{label:"Max gewicht (g)",children:e.jsx("input",{type:"number",min:"0",value:j,onChange:t=>N(t.target.value),className:"w-full"})}),e.jsx(i,{label:"Sortering",children:e.jsx("input",{type:"number",value:k,onChange:t=>S(parseInt(t.target.value||"0",10)),className:"w-full"})}),e.jsx(D,{label:"Actief",control:e.jsx("input",{type:"checkbox",checked:C,onChange:t=>_(t.target.checked),className:"h-4 w-4 accent-brand"})})]})})}export{me 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.