1import{r as t,j as e}from"./vendor-react-GnwsTJfO.js";import{u as q,a as K,b as F}from"./vendor-query-Dp4tHR6-.js";import{N as L,a8 as M,aZ as P,B as i,R as T,a9 as Q,aa as R,ab as I,I as v,a_ as A,ad as z,C as N,g as y,n as H,aA as U,F as Z,f as d,U as n}from"./index-Bj2Y77AF.js";import{e as _,T as G}from"./AdminNavigation-DYLQ05kD.js";import{L as m}from"./label-9b9pu6HH.js";import{T as J}from"./textarea-B-AJzF_c.js";import{A as V,h as W,a as X,b as Y,c as $,d as ee,e as se,f as re,g as ae}from"./alert-dialog-BHHcOqiA.js";import{T as te}from"./trash-2-D673yTlG.js";import"./vendor-cjs-BcELrC9x.js";import"./vendor-supabase-BWPZKnGU.js";import"./vendor-ui-C1xCQL2z.js";import"./vendor-utils-B2rm_Apj.js";import"./MasonicCross-CB_Vslf8.js";import"./users-CHiFHZvy.js";import"./image-l440pP5V.js";const Ne=()=>{const C=q(),[S,l]=t.useState(!1),[a,k]=t.useState(null),[g,u]=t.useState(""),[x,o]=t.useState(""),[b,h]=t.useState(""),[p,c]=t.useState("#3B82F6"),{data:w=[],isLoading:B}=K({queryKey:["tags"],queryFn:async()=>{const{data:s,error:r}=await d.from("tags").select("*").order("name");if(r)throw r;return s}}),j=F({mutationFn:async s=>{if(a){const{error:r}=await d.from("tags").update(s).eq("id",a.id);if(r)throw r}else{const{error:r}=await d.from("tags").insert(s);if(r)throw r}},onSuccess:()=>{C.invalidateQueries({queryKey:["tags"]}),n.success(a?"Tagg oppdatert":"Tagg opprettet"),D(),l(!1)},onError:s=>{console.error("Error saving tag:",s),n.error("Kunne ikke lagre tagg")}}),E=F({mutationFn:async s=>{const{error:r}=await d.from("tags").delete().eq("id",s);if(r)throw r},onSuccess:()=>{C.invalidateQueries({queryKey:["tags"]}),n.success("Tagg slettet")},onError:s=>{console.error("Error deleting tag:",s),n.error("Kunne ikke slette tagg")}}),D=()=>{u(""),o(""),h(""),c("#3B82F6"),k(null)},f=s=>{s?(k(s),u(s.name),o(s.slug),h(s.description||""),c(s.color||"#3B82F6")):D(),l(!0)},O=()=>{if(!g.trim()){n.error("Navn er påkrevd");return}if(!x.trim()){n.error("Slug er påkrevd");return}j.mutate({name:g.trim(),slug:x.trim(),description:b.trim()||null,color:p})};return e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(L,{}),e.jsx(_,{}),e.jsx("main",{className:"flex-1 container mx-auto px-4 py-8",children:e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-sans font-semibold text-3xl",children:"Tagger"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Administrer tagger for å fremheve artikler på forsiden og andre steder"})]}),e.jsxs(M,{open:S,onOpenChange:l,children:[e.jsx(P,{asChild:!0,children:e.jsxs(i,{onClick:()=>f(),children:[e.jsx(T,{className:"h-4 w-4 mr-2"}),"Ny tagg"]})}),e.jsxs(Q,{children:[e.jsx(R,{children:e.jsx(I,{children:a?"Rediger tagg":"Opprett ny tagg"})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"name",children:"Navn *"}),e.jsx(v,{id:"name",value:g,onChange:s=>{u(s.target.value),a||o(A(s.target.value))},placeholder:"F.eks. Forsiden"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"slug",children:"Slug *"}),e.jsx(v,{id:"slug",value:x,onChange:s=>o(A(s.target.value)),placeholder:"f.eks. forsiden"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Brukes internt og i URL-er"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"description",children:"Beskrivelse"}),e.jsx(J,{id:"description",value:b,onChange:s=>h(s.target.value),placeholder:"Kort beskrivelse av taggen (valgfritt)",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"color",children:"Farge"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"color",id:"color",value:p,onChange:s=>c(s.target.value),className:"h-10 w-16 rounded border cursor-pointer"}),e.jsx(v,{value:p,onChange:s=>c(s.target.value),className:"flex-1",placeholder:"#3B82F6"})]})]})]}),e.jsxs(z,{children:[e.jsx(i,{variant:"outline",onClick:()=>l(!1),children:"Avbryt"}),e.jsx(i,{onClick:O,disabled:j.isPending,children:j.isPending?"Lagrer...":a?"Oppdater":"Opprett"})]})]})]})]}),B?e.jsx(N,{children:e.jsx(y,{className:"py-12 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Laster tagger..."})})}):w.length===0?e.jsx(N,{children:e.jsxs(y,{className:"py-12 text-center",children:[e.jsx(G,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Ingen tagger opprettet ennå"}),e.jsxs(i,{variant:"outline",className:"mt-4",onClick:()=>f(),children:[e.jsx(T,{className:"h-4 w-4 mr-2"}),"Opprett første tagg"]})]})}):e.jsx("div",{className:"space-y-3",children:w.map(s=>e.jsx(N,{children:e.jsxs(y,{className:"flex items-center justify-between py-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-4 h-4 rounded-full",style:{backgroundColor:s.color}}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx(H,{variant:"secondary",className:"text-xs",children:s.slug})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(i,{variant:"ghost",size:"icon",onClick:()=>f(s),children:e.jsx(U,{className:"h-4 w-4"})}),e.jsxs(V,{children:[e.jsx(W,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"icon",children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(X,{children:[e.jsxs(Y,{children:[e.jsx($,{children:"Slett tagg"}),e.jsxs(ee,{children:['Er du sikker på at du vil slette taggen "',s.name,'"? Dette vil fjerne taggen fra alle artikler som bruker den.']})]}),e.jsxs(se,{children:[e.jsx(re,{children:"Avbryt"}),e.jsx(ae,{onClick:()=>E.mutate(s.id),className:"bg-destructive hover:bg-destructive/90",children:"Slett"})]})]})]})]})]})},s.id))})]})}),e.jsx(Z,{})]})};export{Ne 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.