import{y as O,eF as U,r as t,R as $,A as B,aV as F,f,B as x,j as i,m as L,l as M,am as V,an as k,ao as G}from"./index-7ecf457b.js";import{N as j,L as W,G as T,d as q}from"./NoRowsComponent-1c8da2c3.js";import{b as J}from"./AdmUsuarios-1abd694f.js";import{D as _}from"./DataGrid-3587fdf7.js";import"./ListItemIcon-6852b595.js";import"./listItemTextClasses-1aee403b.js";import"./Divider-859f9096.js";import"./dividerClasses-c3ed4a16.js";import"./toPropertyKey-4015efc6.js";const y=async(h="4",d="1",o="",c=[],r=1,g=0,l=20)=>(await O.get(`${U}${JSON.stringify({id:h,qp:d,filtro:o,filtros:c})}&&page=${r}&start=${g}&limit=${l}`)).data,oe=h=>{const[d,o]=t.useState([]),[c,r]=t.useState(null),[g,l]=$.useState(!1),{empresaActual:n}=t.useContext(B),[H,p]=t.useState(!0),[N,z]=t.useState(""),[K,D]=t.useState(""),[e,m]=t.useState({pageSize:20,page:0}),[S,C]=t.useState(0),[Q,v]=t.useState(10),u=t.useCallback(F.debounce(async a=>{D(a);const s=await y("4",(n==null?void 0:n.empId)+"",a,[],e.page+1,(e.page+1)*e.pageSize-e.pageSize,e.pageSize);o(s.data.map(w=>({...w,id:w.Identificador})))},1200),[]),A=a=>{const s=a.target.value;z(s),u(s)};t.useEffect(()=>()=>{u.cancel()},[u]);const b=()=>{l(!0)},I=()=>{l(!1),r(null)},E=()=>{l(!0),r(void 0)},P=[{field:"Identificador",headerName:"Id",type:"string",width:100,align:"left",headerAlign:"left"},{field:"Usuario",headerName:"Usuario",type:"string",width:200,align:"left",headerAlign:"left"},{field:"Nombre",headerName:"Nombre",type:"string",width:200,align:"left",headerAlign:"left"},{field:"Sexo",headerName:"Sexo",type:"string",width:200,align:"left",headerAlign:"left"},{field:"Estado",headerName:"Estado",type:"string",width:200,align:"left",headerAlign:"left"},{field:"actions",type:"actions",headerName:"Acciones",width:100,cellClassName:"actions",getActions:({id:a,row:s})=>[i(T,{icon:i(q,{}),label:"Edit",className:"textPrimary",onClick:()=>{b(),r(s)},color:"inherit"},`ABMEdit${a}`)]}],R=async()=>{p(!0);const a=await y("4",(n==null?void 0:n.empId)+"","",[],e.page+1,(e.page+1)*e.pageSize-e.pageSize,e.pageSize);a.success?(o(a.data.map(s=>({...s,id:s.Identificador}))),C(a.total),p(!1)):(C(0),o([]),p(!1))};return t.useEffect(()=>{R()},[e]),f("div",{children:[f(x,{sx:{maxWidth:800},my:2,display:"flex",alignItems:"center",gap:2,children:[i(L,{sx:{color:"#FFF"},variant:"contained",size:"small",onClick:E,children:"Crear usuario"}),i(M,{fullWidth:!0,label:"Buscar...",variant:"outlined",value:N,onChange:A})]}),i(x,{sx:{height:600,width:"100%"},children:i(_,{rows:d,columns:P,editMode:"row",rowsPerPageOptions:[5,10,20,50,100],pagination:!0,paginationMode:"server",rowCount:S||20,page:e.page,components:{NoResultsOverlay:j,LoadingOverlay:W},onPageChange:a=>m({...e,page:a}),pageSize:e.pageSize,onPageSizeChange:a=>{v(a),m({...e,pageSize:a})}})}),f(V,{open:g,onClose:I,maxWidth:"lg",children:[i(k,{id:"scroll-dialog-title",children:"Administración de usuarios"}),i(G,{dividers:!0,children:i(J,{data:c})})]})]})};export{oe as default};
