import{_ as V,n as h,I as C,f as d,i as M,r as l,o as n,b as e,g as m,c as g,t as p,F as x,s as E,A as q,h as D,w as I,e as w,v as b}from"./index-CQUb2PNT.js";import{A as S}from"./AdminLayout-DulJktjC.js";import{L as B}from"./LoadingSpinner-LvNw1Abo.js";import{E as N}from"./ErrorMessage--UUueNY-.js";import{M as L}from"./ModalDialog-CGt-CUTa.js";import"./LogoutButton-Bjoa3U8D.js";const U={class:"admins-page"},j={key:2,class:"success-text"},F={class:"table-container"},O={class:"data-table"},R={class:"input-group"},T={class:"input-group"},z={class:"input-group"},Y={__name:"AdminsView",setup(G){const c=l(!0),i=l(""),u=l(""),v=l([]),f=l(!1),r=l(""),t=l({name:"",email:"",password:""});h(y);async function y(){c.value=!0,i.value="";try{const{data:o}=await C.getAdmins();v.value=o}catch(o){i.value=o.response?.data?.message||"No se pudieron cargar los administradores",v.value=[]}finally{c.value=!1}}function k(){r.value="",t.value={name:"",email:"",password:""},f.value=!0}function _(){f.value=!1}async function A(){r.value="",u.value="";try{await C.createAdmin({name:t.value.name.trim(),email:t.value.email.trim(),password:t.value.password}),u.value="Administrador creado. Ya puede iniciar sesión.",_(),await y()}catch(o){const a=o.response?.data?.errors?Object.values(o.response.data.errors).flat()[0]:o.response?.data?.message;r.value=a||"No se pudo crear el administrador"}}return(o,a)=>(n(),d(S,null,{default:M(()=>[e("div",U,[e("div",{class:"page-header"},[a[3]||(a[3]=e("h1",{class:"header-title"},"ADMINISTRADORES",-1)),e("button",{type:"button",class:"btn btn-gold btn-add",onClick:k},"+ Nuevo administrador")]),a[5]||(a[5]=e("p",{class:"page-lead"}," Creá cuentas para quienes van a usar el panel (monitor, clientes, ajustes). Cada uno inicia sesión con su correo y la contraseña que definís acá. ",-1)),c.value?(n(),d(B,{key:0})):m("",!0),i.value?(n(),d(N,{key:1,message:i.value},null,8,["message"])):m("",!0),u.value?(n(),g("p",j,p(u.value),1)):m("",!0),e("div",F,[e("table",O,[a[4]||(a[4]=e("thead",null,[e("tr",null,[e("th",null,"Nombre"),e("th",null,"Correo"),e("th",null,"Estado")])],-1)),e("tbody",null,[(n(!0),g(x,null,E(v.value,s=>(n(),g("tr",{key:s.id},[e("td",null,p(s.name),1),e("td",null,p(s.email),1),e("td",null,[e("span",{class:q(s.is_active?"status-active":"status-inactive")},p(s.is_active?"Activo":"Inactivo"),3)])]))),128))])])])]),D(L,{show:f.value,title:"Nuevo administrador",onClose:_,onConfirm:A},{default:M(()=>[e("form",{class:"admin-form",onSubmit:I(A,["prevent"])},[e("div",R,[a[6]||(a[6]=e("label",{for:"adm-name"},"Nombre *",-1)),w(e("input",{id:"adm-name","onUpdate:modelValue":a[0]||(a[0]=s=>t.value.name=s),type:"text",class:"input-control",required:"",autocomplete:"name"},null,512),[[b,t.value.name]])]),e("div",T,[a[7]||(a[7]=e("label",{for:"adm-email"},"Correo *",-1)),w(e("input",{id:"adm-email","onUpdate:modelValue":a[1]||(a[1]=s=>t.value.email=s),type:"email",class:"input-control",required:"",autocomplete:"email"},null,512),[[b,t.value.email]])]),e("div",z,[a[8]||(a[8]=e("label",{for:"adm-pass"},"Contraseña *",-1)),w(e("input",{id:"adm-pass","onUpdate:modelValue":a[2]||(a[2]=s=>t.value.password=s),type:"password",class:"input-control",required:"",minlength:"6",autocomplete:"new-password"},null,512),[[b,t.value.password]])]),r.value?(n(),d(N,{key:0,message:r.value},null,8,["message"])):m("",!0)],32)]),_:1},8,["show"])]),_:1}))}},X=V(Y,[["__scopeId","data-v-20ebe00f"]]);export{X as default};
