1import{r as n,e as P,u as q,j as e,H as A,B as o,L as j}from"./index-CRzFJT5-.js";import{u as Q,F as R,a as b,b as p,c as f,d as v,e as C,f as w,g as V,z as J,t as K}from"./form-Dr9aoqJu.js";import{C as y,a as S,b as F,d as N,c as k}from"./card-C-j4uAIC.js";import{I as T}from"./input-OMPQu2El.js";import{T as $,a as G,b as E,c as z,d as U,e as B}from"./table-DEzERuDq.js";import"./label-CcX21Q8R.js";const W=V.extend({name:J.string().min(2,{message:"Categorienaam moet minimaal 2 karakters lang zijn."})});function se(){const[i,D]=n.useState([]),[l,c]=n.useState(!1),[d,g]=n.useState(""),[m,t]=n.useState(""),M=P(),{toast:h}=q(),r=Q({resolver:K(W),defaultValues:{name:"",slug:""}}),u=async()=>{try{const a=await fetch("/api/blog/categories");if(!a.ok)throw new Error("Fout bij ophalen van categorieën");const s=await a.json();D(s)}catch(a){console.error("Fout bij het ophalen van categorieën:",a),t("Fout bij het ophalen van categorieën. Probeer het later opnieuw.")}};n.useEffect(()=>{u()},[]);const H=a=>a.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),I=a=>{const s=a.target.value,x=H(s);r.setValue("slug",x)},L=async a=>{c(!0),t(""),g("");try{const s=await fetch("/api/blog/categories",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!s.ok){const O=await s.json();throw new Error(O.message||"Er is een fout opgetreden")}const x=await s.json();g("Categorie succesvol aangemaakt!"),h({title:"Categorie aangemaakt!",description:"De categorie is succesvol aangemaakt.",variant:"default"}),r.reset(),u(),M.invalidateQueries({queryKey:["/api/blog/categories"]})}catch(s){console.error("Fout bij verzenden formulier:",s),t("Er is een fout opgetreden bij het aanmaken van de categorie. Probeer het opnieuw."),h({title:"Fout!",description:"De categorie kon niet worden aangemaakt.",variant:"destructive"})}finally{c(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(A,{children:[e.jsx("meta",{name:"description",content:"Admin interface voor het beheren van blog categorieën van Sleutelslim.nl"}),e.jsx("meta",{name:"robots",content:"noindex, nofollow"})]}),e.jsxs("div",{className:"container mx-auto py-8 max-w-4xl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Categorieën beheren"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o,{variant:"outline",asChild:!0,children:e.jsx(j,{href:"/blog",children:"Terug naar blog"})}),e.jsx(o,{variant:"outline",asChild:!0,children:e.jsx(j,{href:"/admin/blog",children:"Blogbericht toevoegen"})})]})]}),d&&e.jsx("div",{className:"bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-6",children:d}),m&&e.jsx("div",{className:"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-6",children:m}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(y,{children:[e.jsxs(S,{children:[e.jsx(F,{children:"Nieuwe categorie"}),e.jsx(N,{children:"Maak een nieuwe categorie aan voor blogberichten."})]}),e.jsx(k,{children:e.jsx(R,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(L),className:"space-y-6",children:[e.jsx(b,{control:r.control,name:"name",render:({field:a})=>e.jsxs(p,{children:[e.jsx(f,{children:"Naam"}),e.jsx(v,{children:e.jsx(T,{placeholder:"Categorienaam",...a,onChange:s=>{a.onChange(s),I(s)}})}),e.jsx(C,{children:"De naam van de categorie die zichtbaar is op de website."}),e.jsx(w,{})]})}),e.jsx(b,{control:r.control,name:"slug",render:({field:a})=>e.jsxs(p,{children:[e.jsx(f,{children:"Slug"}),e.jsx(v,{children:e.jsx(T,{placeholder:"categorie-slug",...a})}),e.jsx(C,{children:"De slug wordt automatisch gegenereerd, maar kan indien nodig worden aangepast."}),e.jsx(w,{})]})}),e.jsx(o,{type:"submit",className:"w-full",disabled:l,children:l?"Bezig met opslaan...":"Categorie aanmaken"})]})})})]}),e.jsxs(y,{children:[e.jsxs(S,{children:[e.jsx(F,{children:"Bestaande categorieën"}),e.jsx(N,{children:"Overzicht van alle categorieën voor blogberichten."})]}),e.jsx(k,{children:i.length===0?e.jsx("div",{className:"text-center py-6 text-gray-500",children:"Nog geen categorieën aangemaakt."}):e.jsxs($,{children:[e.jsx(G,{children:e.jsxs(E,{children:[e.jsx(z,{children:"Naam"}),e.jsx(z,{children:"Slug"})]})}),e.jsx(U,{children:i.map(a=>e.jsxs(E,{children:[e.jsx(B,{className:"font-medium",children:a.name}),e.jsx(B,{children:a.slug})]},a.id))})]})})]})]})]})]})}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.