1import{r,H as e,aO as i,a8 as ne,aT as le,aU as y,aP as d,bb as oe,bc as ce,a2 as B,a1 as o,bd as de,aR as ue,be as xe,aq as he,bf as me,U as L,a3 as M,ah as N,b1 as P,b2 as R,b3 as U,ad as fe,S as ge,a9 as h,b4 as W,bg as je,a0 as pe}from"./vendor-DuAiEDbE.js";import"./index-DXK9TXc8.js";import{g as ve,u as Ce,c as be,d as Se}from"./categories.service-CcD9iWCM.js";import{U as ye,a as we}from"./useCases-B9W9yJEH.js";import{l as Ie}from"./locale-Rog6nREm.js";import{u as De}from"./useResponsive-BDgn-Q4p.js";import{d as Ee,x as ke,G as Ae,H as Fe,J as Te,K as _e,M as Oe}from"./vendor-mui-icons-lTdDhYAN.js";import{D as ze}from"./vendor-mui-grid-BNwuG0uS.js";function Ge(){const{isMobile:w}=De(),[G,I]=r.useState([]),[D,E]=r.useState(!0),[k,m]=r.useState(null),[A,F]=r.useState(null),[l,f]=r.useState(null),[q,g]=r.useState(!1),[H,T]=r.useState(!1),[a,u]=r.useState({en:"",es:"",active:!0,use_cases:[]}),[_,j]=r.useState(null),[p,v]=r.useState(null),[O,V]=r.useState(""),[z,J]=r.useState(!1),[x,C]=r.useState("all");r.useEffect(()=>{(async()=>{await b()})()},[]);const b=async()=>{try{E(!0),m(null);const s=await ve();I(Array.isArray(s)?s:[])}catch(s){s instanceof Error?m(s.message):m("Error desconocido"),I([]),console.error(s)}finally{E(!1)}},K=(s,t)=>{F(s.currentTarget),f(t)},S=()=>{F(null)},Q=()=>{u({en:"",es:"",active:!0,use_cases:[]}),j(null),v(null),g(!0)},X=()=>{l&&(u(l),j(null),v(l.icon_url||null),g(!0)),S()},Y=s=>{f(s),T(!0)},Z=()=>{l&&(Y(l),S())},c=()=>{g(!1),T(!1),f(null)},$=async()=>{try{const s={en:a.en,es:a.es,active:a.active,use_cases:a.use_cases??[]};a.id?await Ce(a.id,s,_):await be(s,_),b(),c()}catch(s){console.error("Error al guardar:",s)}},ee=async()=>{if(l)try{await Se(l.id),b(),c()}catch(s){console.error("Error al borrar:",s)}},se=s=>{V(s.target.value)},te=G.filter(s=>{const t=O.toLowerCase(),n=s.id.toString().includes(t)||s.es.toLowerCase().includes(t)||s.en.toLowerCase().includes(t);return x==="active"&&!s.active||x==="inactive"&&s.active?!1:n}),ae=[{field:"id",headerName:"ID",width:70},{field:"icon_url",headerName:"Icono",width:70,sortable:!1,filterable:!1,renderCell:s=>s.value?e.jsx(i,{sx:{display:"flex",alignItems:"center",height:"100%"},children:e.jsx("img",{src:s.value,alt:"",width:32,height:32,style:{objectFit:"contain"}})}):null},{field:"es",headerName:"Nombre",flex:1,minWidth:150},{field:"use_cases",headerName:"Servicios sugeridos",flex:1,minWidth:200,sortable:!1,filterable:!1,renderCell:s=>{const t=s.value??[];return t.length===0?e.jsx(h,{label:"Todos",size:"small",variant:"outlined"}):e.jsx(i,{sx:{display:"flex",gap:.5,flexWrap:"wrap",alignItems:"center",height:"100%"},children:t.map(n=>e.jsx(h,{label:we[n]??n,size:"small"},n))})}},{field:"active",headerName:"Estado",width:120,renderCell:s=>e.jsx(h,{label:s.value?"Activo":"Inactivo",color:s.value?"success":"default",size:"small"})},{field:"actions",headerName:"Acciones",type:"actions",width:100,align:"right",headerAlign:"right",renderCell:s=>e.jsx(pe,{onClick:t=>K(t,s.row),children:e.jsx(Oe,{})})}];return D?e.jsx(i,{sx:{display:"flex",justifyContent:"center",mt:4},children:e.jsx(ne,{})}):k?e.jsx(le,{severity:"error",sx:{m:2},children:k}):e.jsxs(i,{sx:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[e.jsxs(i,{children:[e.jsx(i,{sx:{p:2},children:e.jsxs(y,{container:!0,spacing:2,alignItems:"center",children:[e.jsxs(y,{size:{xs:12,md:6},children:[e.jsx(d,{variant:"h4",fontWeight:"bold",children:"Gestión de CategorÃas"}),e.jsxs(oe,{sx:{mt:1},children:[e.jsx(ce,{underline:"hover",color:"inherit",href:"/dashboard",children:"Inicio"}),e.jsx(d,{color:"text.primary",children:"CategorÃas"})]})]}),e.jsx(y,{size:{xs:12,md:6},children:e.jsxs(i,{sx:{display:"flex",justifyContent:{xs:"stretch",md:"flex-end"},gap:1,flexWrap:"wrap"},children:[e.jsx(B,{variant:"outlined",size:"small",placeholder:"Buscar por ID o nombre...",value:O,onChange:se,sx:{width:{xs:"100%",sm:250}},InputProps:{startAdornment:e.jsx(Ee,{sx:{mr:1,color:"text.secondary"}})}}),e.jsx(o,{variant:"contained",startIcon:e.jsx(ke,{}),onClick:Q,sx:{flex:{xs:1,sm:"none"}},children:"Agregar"}),e.jsx(o,{variant:"outlined",startIcon:e.jsx(Ae,{}),onClick:()=>J(s=>!s),sx:{flex:{xs:1,sm:"none"}},children:z?"Ocultar":"Filtros"})]})})]})}),e.jsx(de,{in:z,unmountOnExit:!0,children:e.jsxs(ue,{elevation:2,sx:{m:2,p:2,mt:0},children:[e.jsx(d,{variant:"subtitle1",gutterBottom:!0,children:"Filtrar por estado:"}),e.jsxs(xe,{children:[e.jsx(o,{variant:x==="all"?"contained":"outlined",onClick:()=>C("all"),children:"Todos"}),e.jsx(o,{variant:x==="active"?"contained":"outlined",onClick:()=>C("active"),children:"Activos"}),e.jsx(o,{variant:x==="inactive"?"contained":"outlined",onClick:()=>C("inactive"),children:"Inactivos"})]})]})})]}),e.jsx(i,{sx:{flex:1,p:2,pt:0,overflow:"auto"},children:e.jsx(he,{elevation:2,sx:{height:"100%",width:"100%"},children:e.jsx(ze,{rows:te,columns:ae,loading:D,pageSizeOptions:[10,25,50],initialState:{pagination:{paginationModel:{pageSize:10}}},localeText:Ie,disableRowSelectionOnClick:!0,columnVisibilityModel:{id:!w,en:!w},sx:{border:"none",fontSize:{xs:"12px",md:"14px"}}})})}),e.jsxs(me,{anchorEl:A,open:!!A,onClose:S,children:[e.jsxs(L,{onClick:X,children:[e.jsx(M,{children:e.jsx(Fe,{fontSize:"small"})}),e.jsx(N,{children:"Editar"})]}),e.jsxs(L,{onClick:Z,children:[e.jsx(M,{children:e.jsx(Te,{fontSize:"small"})}),e.jsx(N,{children:"Borrar"})]})]}),e.jsxs(P,{open:q,onClose:c,children:[e.jsx(R,{children:a.id?"Editar CategorÃa":"Nueva CategorÃa"}),e.jsxs(U,{children:[e.jsx(B,{autoFocus:!0,margin:"dense",label:"Nombre",type:"text",fullWidth:!0,variant:"outlined",value:a.es,onChange:s=>u({...a,es:s.target.value})}),e.jsx(fe,{control:e.jsx(ge,{checked:a.active,onChange:s=>u({...a,active:s.target.checked})}),label:"Activo"}),e.jsxs(i,{sx:{mt:2},children:[e.jsx(d,{variant:"subtitle2",gutterBottom:!0,children:"Servicios sugeridos"}
1),e.jsx(d,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1},children:"Al publicar un sitio de esta categorÃa se ofrecerán estos servicios. Si no eliges ninguno, se muestran todos."}),e.jsx(i,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:ye.map(s=>{const t=(a.use_cases??[]).includes(s.key);return e.jsx(h,{label:s.title,color:t?"primary":"default",variant:t?"filled":"outlined",onClick:()=>{const n=a.use_cases??[],re=t?n.filter(ie=>ie!==s.key):[...n,s.key];u({...a,use_cases:re})}},s.key)})})]}),e.jsxs(i,{sx:{mt:2},children:[e.jsx(d,{variant:"subtitle2",gutterBottom:!0,children:"Icono"}),e.jsxs(i,{sx:{display:"flex",alignItems:"center",gap:2},children:[p&&e.jsx("img",{src:p,alt:"Preview",width:48,height:48,style:{objectFit:"contain",borderRadius:4,border:"1px solid #ddd"}}),e.jsxs(o,{component:"label",variant:"outlined",size:"small",startIcon:e.jsx(_e,{}),children:[p?"Cambiar":"Subir icono",e.jsx("input",{type:"file",hidden:!0,accept:"image/*",onChange:s=>{var n;const t=((n=s.target.files)==null?void 0:n[0])||null;j(t),t&&v(URL.createObjectURL(t))}})]})]})]})]}),e.jsxs(W,{children:[e.jsx(o,{onClick:c,children:"Cancelar"}),e.jsx(o,{onClick:$,variant:"contained",children:"Guardar"})]})]}),e.jsxs(P,{open:H,onClose:c,children:[e.jsx(R,{children:"Confirmar Borrado"}),e.jsx(U,{children:e.jsxs(je,{children:['¿Estás seguro de que deseas eliminar la categorÃa "',l==null?void 0:l.es,'"? Esta acción no se puede deshacer.']})}),e.jsxs(W,{children:[e.jsx(o,{onClick:c,children:"Cancelar"}),e.jsx(o,{onClick:ee,color:"error",children:"Eliminar"})]})]})]})}export{Ge 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.