1import{aU as S,r as d,j as e,l as j,B as n,aV as N,aW as T,a4 as L,aX as v,Z as F}from"./index-BwOzJ6eq.js";import{R as y}from"./refresh-cw-CtFLMUn_.js";import{P as w}from"./pencil-ClY9HOqe.js";import{E as P}from"./eye-off-C3CVc90d.js";import{E as R}from"./eye-DdvwveBy.js";const C={label:"",slug:"",category:"problem",description:"",sort_order:0};function X(){const{tags:m,isLoading:k,error:u,refetch:x,createTag:_,updateTag:p,isCreating:E,isUpdating:h}=S({includeInactive:!0}),[t,l]=d.useState(C),[i,b]=d.useState(null),[o,c]=d.useState(!1),q=d.useMemo(()=>m.reduce((s,r)=>(s[r.category].push(r),s),{problem:[],club:[],goal:[],content_type:[]}),[m]),f=()=>{l(C),b(null),c(!1)},O=s=>{b(s.id),c(!0),l({label:s.label,slug:s.slug,category:s.category,description:s.description||"",sort_order:s.sort_order})},z=async s=>{s.preventDefault();const r={label:t.label,slug:t.slug,category:t.category,description:t.description,sort_order:Number(t.sort_order)||0};i?await p({id:i,input:r}):await _(r),f()};if(k)return e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(j,{className:"h-8 w-8 animate-spin text-primary"})});if(u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4",children:[e.jsxs("p",{className:"text-destructive",children:["Error al cargar etiquetas: ",u.message]}),e.jsxs(n,{onClick:()=>x(),variant:"outline",children:[e.jsx(y,{className:"mr-2 h-4 w-4"}),"Reintentar"]})]});const g=E||h;return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden p-4 md:p-6",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3 md:mb-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl font-bold text-foreground md:text-2xl",children:"Etiquetas"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Problemas, palos, objetivos y tipos de contenido usados en descubrimiento."})]}),e.jsxs(n,{onClick:()=>x(),variant:"outline",size:"sm",className:"shrink-0",children:[e.jsx(y,{className:"h-4 w-4 md:mr-2"}),e.jsx("span",{className:"hidden md:inline",children:"Actualizar"})]})]}),e.jsxs(n,{variant:o?"secondary":"default",size:"sm",className:"mb-3 w-full md:hidden",onClick:()=>c(s=>!s),children:[e.jsx(N,{className:"mr-2 h-4 w-4"}),o?"Cerrar formulario":i?"Editar etiqueta":"Nueva etiqueta"]}),e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-1 gap-4 md:grid-cols-[360px_minmax(0,1fr)] md:gap-6",children:[e.jsxs("form",{onSubmit:z,className:`h-fit roun
1ded-lg border bg-card p-4 ${o?"":"hidden md:block"}`,children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-5 w-5 text-primary"}),e.jsx("h2",{className:"font-semibold text-foreground",children:i?"Editar etiqueta":"Nueva etiqueta"})]}),i&&e.jsx("button",{type:"button",onClick:f,className:"rounded-full p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Cancelar edición",children:e.jsx(L,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("label",{className:"block space-y-1.5 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Nombre visible"}),e.jsx("input",{value:t.label,onChange:s=>l(r=>({...r,label:s.target.value})),required:!0,maxLength:80,className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary/40",placeholder:"Eliminar mi slice"})]}),e.jsxs("label",{className:"block space-y-1.5 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Slug"}),e.jsx("input",{value:t.slug,onChange:s=>l(r=>({...r,slug:s.target.value})),maxLength:80,className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary/40",placeholder:"eliminar-mi-slice"})]}),e.jsxs("label",{className:"block space-y-1.5 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:"CategorÃa"}),e.jsx("select",{value:t.category,onChange:s=>l(r=>({...r,category:s.target.value})),className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary/40",children:Object.entries(v).map(([s,r])=>e.jsx("option",{value:s,children:r},s))})]}),e.jsxs("label",{className:"block space-y-1.5 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Descripción interna"}),e.jsx("textarea",{value:t.description,onChange:s=>l(r=>({...r,description:s.target.value})),rows:3,maxLength:240,className:"w-full resize-none rounded-md border border-border bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary/40",placeholder:"Cuándo debe usarse esta etiqueta"})]}),e.jsxs("label",{className:"block space-y-1.5 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Orden"}),e.jsx("input",{type:"number",value:t.sort_order,onChange:s=>l(r=>({...r,sort_order:Number(s.target.value)})),className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary/40"})]})]}),e.jsxs(n,{type:"submit",className:"mt-5 w-full",disabled:g||!t.label.trim(),children:[g?e.jsx(j,{className:"mr-2 h-4 w-4 animate-spin"}):i?e.jsx(w,{className:"mr-2 h-4 w-4"}):e.jsx(N,{className:"mr-2 h-4 w-4"}),i?"Guardar cambios":"Crear etiqueta"]})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto rounded-lg border bg-card",children:Object.entries(q).map(([s,r])=>e.jsxs("section",{className:"border-b border-border last:border-b-0",children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between bg-card/95 px-4 py-3 pt-safe-t-3 backdrop-blur",children:[e.jsx("h2",{className:"font-semibold text-foreground",children:v[s]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.length," etiquetas"]})]}),e.jsxs("div",{className:"divide-y divide-border",children:[r.map(a=>e.jsxs("div",{className:F("grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3 px-3 py-3 md:grid-cols-[minmax(0,1fr)_96px_112px] md:gap-4 md:px-4",!a.is_active&&"bg-muted/30 text-muted-foreground"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate font-medium text-foreground",children:a.label}),!a.is_active&&e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground",children:"Oculta"})]}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["/",a.slug,e.jsxs("span",{className:"md:hidden",children:[" · orden ",a.sort_order]})]}),a.description&&e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:a.description})]}),e.jsxs("p",{className:"hidden text-sm text-muted-foreground md:block",children:["Orden ",a.sort_order]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(n,{variant:"outline",size:"sm",onClick:()=>O(a),children:e.jsx(w,{className:"h-4 w-4"})}),e.jsx(n,{variant:"outline",size:"sm",onClick:()=>
1p({id:a.id,input:{is_active:!a.is_active}}),disabled:h,children:a.is_active?e.jsx(P,{className:"h-4 w-4"}):e.jsx(R,{className:"h-4 w-4"})})]})]},a.id)),r.length===0&&e.jsx("div",{className:"px-4 py-6 text-sm text-muted-foreground",children:"No hay etiquetas en esta categorÃa."})]})]},s))})]})]})}export{X 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.