1import{r,G as e,aN as b,aO as y,a0 as u,aS as L,be as R,T as E,a2 as w,ag as z,b0 as T,b1 as k,b2 as D,b3 as I,aZ as B,S as _,$ as H,aT as o,a1 as g,ac as V}from"./vendor-BvYDHPOR.js";import{g as P,a as U,d as Y,u as G,c as q}from"./guides.service-C9pzXosO.js";import{l as J}from"./locale-Rog6nREm.js";import{N as Z}from"./NumberField-1poEN72n.js";import{W as $}from"./wysiwygEditor-DSfWM-eE.js";import{an as K,x as Q,H as X,J as ee,ao as te,M as ae}from"./vendor-mui-icons-CrMwg7iZ.js";import{D as le}from"./vendor-mui-grid-C7uZP1uA.js";import"./index-CQWuR6TJ.js";const se={title:"",description:"",content:"",youtube_url:"",sort_order:0,active:!0};function me(){const[s,x]=r.useState([]),[c,t]=r.useState(!0),[i,n]=r.useState(""),[h,d]=r.useState(null),[a,v]=r.useState(null),[N,m]=r.useState(!1),[C,S]=r.useState(null),[W,j]=r.useState(!1),p=async()=>{t(!0);try{x(await U())}catch{n("Error al cargar tutoriales")}finally{t(!1)}};r.useEffect(()=>{p()},[]);const O=(l,f)=>{d(l.currentTarget),v(f)},A=async l=>{try{await G(l.id,{active:l.active!==1}),p()}catch{n("Error al actualizar")}},F=async()=>{if(a)try{await Y(a.id),n("Tutorial eliminado"),p()}catch{n("Error al eliminar")}finally{j(!1),v(null)}},M=[{field:"sort_order",headerName:"Orden",width:80},{field:"title",headerName:"TÃtulo",flex:1,minWidth:180},{field:"youtube_url",headerName:"Video",width:90,sortable:!1,renderCell:({value:l})=>l?e.jsx(te,{fontSize:"small",color:"error"}):e.jsx("span",{style:{color:"#bbb"},children:"â"})},{field:"active",headerName:"Activo",width:90,renderCell:({row:l})=>e.jsx(_,{checked:l.active===1,onChange:()=>A(l),size:"small"})},{field:"actions",headerName:"",width:60,sortable:!1,renderCell:({row:l})=>e.jsx(H,{size:"small",onClick:f=>O(f,l),children:e.jsx(ae,{fontSize:"small"})})}];return e.jsxs(b,{children:[e.jsxs(b,{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2,gap:1,children:[e.jsx(y,{variant:"h5",fontWeight:700,children:"Tutoriales y guÃas"}),e.jsx(u,{size:"small",startIcon:e.jsx(K,{}),onClick:()=>window.open(P(),"_blank"),children:"Ver página"})]}),e.jsxs(b,{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2,children:[e.jsx(L,{severity:"info",sx:{flex:1,mr:2},children:"Esta es la biblioteca central de tutoriales. Se muestra en la web pública, en el panel del cliente y en la app de negocios."}),e.jsx(u,{variant:"contained",startIcon:e.jsx(Q,{}),onClick:()=>{S(null),m(!0)},children:"Nuevo tutorial"})]}),e.jsx(le,{rows:s,columns:M,loading:c,autoHeight:!0,rowHeight:56,pageSizeOptions:[10,25],initialState:{pagination:{paginationModel:{pageSize:10}}},localeText:J,disableRowSelectionOnClick:!0,sx:{bgcolor:"white",borderRadius:2}}),e.jsxs(R,{anchorEl:h,open:!!h,onClose:()=>d(null),children:[e.jsxs(E,{onClick:()=>{S(a.id),d(null),m(!0)},children:[e.jsx(w,{children:e.jsx(X,{fontSize:"small"})}),e.jsx(z,{children:"Editar"})]}),e.jsxs(E,{onClick:()=>{d(null),j(!0)},children:[e.jsx(w,{children:e.jsx(ee,{fontSize:"small",color:"error"})}),e.jsx(z,{sx:{color:"error.main"},children:"Eliminar"})]})]}),N&&e.jsx(re,{guide:C&&s.find(l=>l.id===C)||null,onClose:()=>m(!1),onSaved:l=>{m(!1),n(l),p()}}),e.jsxs(T,{open:W,onClose:()=>j(!1),children:[e.jsx(k,{children:"Eliminar tutorial"}),e.jsx(D,{children:e.jsx(y,{children:"¿Eliminar este tutorial? Esta acción no se puede deshacer."})}),e.jsxs(I,{children:[e.jsx(u,{onClick:()=>j(!1),children:"Cancelar"}),e.jsx(u,{variant:"contained",color:"error",onClick:F,children:"Eliminar"})]})]}),e.jsx(B,{open:!!i,autoHideDuration:3e3,onClose:()=>n(""),message:i})]})}function re({guide:s,onClose:x,onSaved:c}){const[t,i]=r.useState(s?{title:s.title,description:s.description||"",content:s.content||"",youtube_url:s.youtube_url||"",sort_order:s.sort_order,active:s.active===1}:se),[n,h]=r.useState(!1),d=async()=>{if(!t.title.trim()){c("El tÃtulo es obligatorio");return}h(!0);try{s?(await G(s.id,t),c("Tutorial actualizado")):(await q(t),c("Tutorial creado"))}catch{c("Error al guardar")}finally{h(!1)}};return e.jsxs(T,{open:!0,onClose:x,maxWidth:"md",fullWidth:!0,children:[e.jsx(k,{children:s?"Editar tutorial":"Nuevo tutorial"}),e.jsx(D,{children:e.jsxs(o,{container:!0,spacing:2,sx:{mt:.5},children:[e.jsx(o,{size:{xs:12,sm:9},children:e.jsx(g,{fullWidth:!0,size:"small",label:"TÃtulo",required:!0,value:t.title,onChange:a=>i({...t,title:a.target.value})})}),e.jsx(o,{size:{xs:12,sm:3},children:e.jsx(Z,{fullWidth:!0,size:"small",label:"Orden",integer:!0,value:t.sort_order,onChange:a=>i({...t,sort_order:a??0})})}),e.jsx(o,{size:12,children:e.jsx(g,{fullWidth:!0,size:"small",label:"Descripción corta (opcional)",value:t.description||"",onChange:a=>i({...t,description:a.target.value}),helperText:"Se muestra bajo el tÃtulo en la lista"})}),e.jsx(o,{size:12,children:e.jsx(g,{fullWidth:!0,size:"small",label:"Video de YouTube (opcional)",value:t.youtube_url||"",onChange:a=>i({...t,youtube_url:a.target.value}),helperText:"Pega la URL del video (youtube.com/watch, youtu.be, shorts...)"})}),e.jsxs(o,{size:12,children:[e.jsx(y,{variant:"body2",fontWeight:600,sx:{mb:.5},children:"Contenido (opcional)"}),e.jsx($,{value:t.content||"",onChange:a=>i({...t,content:a.target.value}),placeholder:"Escribe el texto del tutorial..."})]}),e.jsx(o,{size:12,children:e.jsx(V,{control:e.jsx(_,{checked:t.active,onChange:a=>i({...t,active:a.target.checked})}),label:"Activo"})})]})}),e.jsxs(I,{sx:{px:3,pb:2},children:[e.jsx(u,{onClick:x,children:"Cancelar"}),e.jsx(u,{variant:"contained",onClick:d,disabled:n,children:n?"Guardando...":s?"Guardar":"Crear"})]})]})}export{me 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.