import{r as m,S as L,j as e,a as k,f as I}from"./app-BZJf8lgN.js";import{I as h}from"./InputLabel-Dd3VnoK3.js";import{T as R}from"./toast.esm-CYGIlaDH.js";import{B as l}from"./button.esm-D_cwsnQR.js";import{L as _}from"./layout-DZ5xjWdd.js";import{D as B,C as c}from"./column.esm-BrHEUUD7.js";import{D as f}from"./dialog.esm-B_DzXfDY.js";import{I as n}from"./inputtext.esm-B1lZn37a.js";import{C as V,c as F}from"./confirmdialog.esm-DF1Ea2vk.js";import{D as j}from"./dropdown.esm-HqLoOpxI.js";import{M as t}from"./message.esm-Do6SkgWF.js";import"./csstransition.esm-BNRxTMOa.js";import"./hooks.esm-UVLztt_0.js";import"./CSSTransition-DBuKQJwM.js";import"./index.esm-CygY3Qsw.js";import"./index.esm-B5zYYMSp.js";import"./index.esm-hRnQzR_k.js";import"./index.esm-mvXJc0W-.js";import"./overlayservice.esm-B-BnP5c1.js";import"./index.esm-Ckth6fI3.js";const te=({usuarios:v,roles:p})=>{const i=m.useRef(null),[y,u]=m.useState(!1),[g,d]=m.useState(!1),{data:o,setData:a,post:b,put:w,errors:r,reset:x}=L({username:"",rol:null}),U=s=>{s.preventDefault(),b(route("usuarios.store"),{onSuccess:()=>{i.current.show({severity:"success",summary:"Exito",detail:"Usuario Agregado/a",life:3e3}),x(),u(!1)}})},N=s=>{s.preventDefault(),w(route("usuarios.update",o.id),{onSuccess:()=>{d(!1),i.current.show({severity:"success",summary:"Exito",detail:"Usuario Actualizado/a",life:3e3}),x()}})},S=s=>{F({message:"Esta seguro/a que desea eliminar un Usuario?",header:"Eliminar Usuario",icon:"pi pi-exclamation-triangle",defaultfocus:"accept",accept:()=>D(s),reject:E})},C=s=>{a({id:s.id,username:s.username,rol:s.rol_id}),d(!0)},D=s=>{I.delete(route("usuarios.destroy",s),{onSuccess:()=>{i.current.show({severity:"info",summary:"Usuario Eliminado",detail:"Se ha eliminado un Usuario",life:3e3})}})},E=()=>{i.current.show({severity:"warn",summary:"Cancelado",detail:"No se ha eliminado nada",life:3e3}),setDeleteDistributorId(null)},A=s=>e.jsx(e.Fragment,{children:s.rol_id==1?"Administrador":"Usuario"}),T=s=>e.jsxs(e.Fragment,{children:[" ",e.jsx(l,{type:"button",icon:"pi pi-pencil",onClick:()=>C(s)})," ",e.jsx(l,{type:"button",icon:"pi pi-times",severity:"danger",onClick:()=>S(s.id)})," "]});return e.jsxs(_,{children:[e.jsx(f,{header:"Agregar Usuario ",visible:y,style:{width:"50vw"},onHide:()=>u(!1),children:e.jsxs("form",{onSubmit:U,encType:"multipart/form-data",children:[e.jsx(n,{name:"usuario",placeholder:"usuario",className:`w-full mb-2 ${r.usuario?"p-invalid":""}`,onChange:s=>a("username",s.target.value)}),r.username&&e.jsx(t,{severity:"error",text:r.username}),e.jsx(n,{type:"password",name:"password",placeholder:"password",className:`w-full mb-2 ${r.password?"p-invalid":""}`,onChange:s=>a("password",s.target.value)}),r.password&&e.jsx(t,{severity:"error",text:r.password}),e.jsx(h,{children:"Rol"}),e.jsx(j,{value:o.rol,className:"w-full",placeholder:"Seleccionar rol del usuario",options:p,optionLabel:"nombre_rol",optionValue:"id",onChange:s=>a("rol",s.target.value)}),r.rol&&e.jsx(t,{severity:"error",text:r.rol}),e.jsx(l,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Agregar Usuario "})]})}),e.jsx(f,{header:"Editar Usuario ",visible:g,style:{width:"50vw"},onHide:()=>d(!1),children:e.jsxs("form",{onSubmit:N,children:[e.jsx(n,{name:"usuario",placeholder:"usuario",value:(o==null?void 0:o.username)||"",className:"w-full mb-2",onChange:s=>a("username",s.target.value)}),r.username&&e.jsx(t,{severity:"error",text:r.username}),e.jsx(n,{name:"password",placeholder:"password",className:"w-full mb-2",onChange:s=>a("password",s.target.value)}),r.password&&e.jsx(t,{severity:"error",text:r.password}),e.jsx(h,{children:"Rol"}),e.jsx(j,{className:"w-full",placeholder:"Seleccionar rol del usuario",value:o.rol,options:p,optionLabel:"nombre_rol",optionValue:"id",onChange:s=>a("rol",s.target.value)}),r.rol&&e.jsx(t,{severity:"error",text:r.rol}),e.jsx(l,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Editar Usuario "})]})}),e.jsx(V,{}),e.jsx(k,{title:"Editar Usuarios"}),e.jsx("div",{className:"grid",children:e.jsx("div",{className:"col-md-12",children:e.jsxs("div",{className:"card",children:[e.jsx("div",{className:"card-header",style:{marginLeft:"80%"},children:e.jsx(l,{onClick:()=>{u(!0)},className:"mb-2",children:"Agregar Usuario"})}),e.jsx(R,{ref:i}),e.jsxs(B,{value:v,tableStyle:{minWidth:"50rem"},children:[e.jsx(c,{field:"username",header:"Usuario"}),e.jsx(c,{field:"role_id",header:"Rol",body:A}),e.jsx(c,{header:"Acciones",body:T})]})]})})})]})};export{te as default};
//# sourceMappingURL=Usuarios-CnlDcKjb.js.map
