import{i as e}from"./chunk-aKtaBQYM.js";import{N as t,Vt as n,wt as r}from"./mui-B6lh3XSP.js";import{l as i}from"./IconButton-BEBOUWhl.js";import{n as a}from"./MenuItem-HQNtf0LG.js";import{n as o,t as s}from"./SearchHeader-CmohWzoP.js";import{t as c}from"./Switch-CYlSLZf7.js";import{t as l}from"./TableHead-_KJlbpnj.js";import{At as u,D as d,Dt as f,Et as p,G as m,Ot as h,Q as g,Wt as _,_t as v,mt as y,pt as b,w as x,wt as S,yt as C,zt as w}from"./index-KVuxnkWj.js";import{t as T}from"./CollectionActions-CDxOJIb6.js";import{t as E}from"./TableShimmer-f7Cf4NTV.js";import{n as D,t as O}from"./useSettingsStyles-X3caKosH.js";import{t as k}from"./Link-C46sYcuF.js";var A=e(n(),1),j=r(),M=t((0,j.jsx)(`path`,{d:`M11 7 9.6 8.4l2.6 2.6H2v2h10.2l-2.6 2.6L11 17l5-5zm9 12h-8v2h8c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2h-8v2h8z`}),`Login`),N=({userId:e})=>{let t=C(),[n,r]=(0,A.useState)(),i=y(async()=>{r(await(await x(`/api/devices?${new URLSearchParams({userId:e}).toString()}`)).json())});return n?n.length:(0,j.jsx)(w,{href:`#`,onClick:i,children:t(`reportShow`)})},P=()=>{let{classes:e}=O(),t=i(),n=C(),r=d(),[w,P]=(0,A.useReducer)(e=>e+1,0),[F,I]=(0,A.useState)([]),[L,R]=(0,A.useState)(``),[z,B]=(0,A.useState)(!0),[V,H]=(0,A.useState)(!1),U=y(async e=>{await x(`/api/session/${e}`),window.location.replace(`/`)}),W={key:`login`,title:n(`loginLogin`),icon:(0,j.jsx)(M,{fontSize:`small`}),handler:U},G={key:`connections`,title:n(`sharedConnections`),icon:(0,j.jsx)(k,{fontSize:`small`}),handler:e=>t(`/settings/user/${e}/connections`)},K=(0,A.useCallback)(async(e,t)=>{let n=new URLSearchParams({excludeAttributes:!0,limit:50,offset:e});L&&n.append(`keyword`,L);let r=await(await x(`/api/users?${n.toString()}`,{signal:t})).json();I(t=>e?[...t,...r]:r),B(r.length>=50)},[L]),q=v(()=>K(F.length));return b(async({signal:e})=>{I([]),await K(0,e)},[w,K]),(0,j.jsxs)(a,{menu:(0,j.jsx)(D,{}),breadcrumbs:[`settingsTitle`,`settingsUsers`],children:[(0,j.jsx)(s,{keyword:L,setKeyword:R}),(0,j.jsxs)(u,{className:e.table,children:[(0,j.jsx)(l,{children:(0,j.jsxs)(S,{children:[(0,j.jsx)(f,{children:n(`sharedName`)}),(0,j.jsx)(f,{children:n(`userEmail`)}),(0,j.jsx)(f,{children:n(`userAdmin`)}),(0,j.jsx)(f,{children:n(`sharedDisabled`)}),(0,j.jsx)(f,{children:n(`userExpirationTime`)}),(0,j.jsx)(f,{children:n(`deviceTitle`)}),(0,j.jsx)(f,{className:e.columnAction})]})}),(0,j.jsxs)(h,{children:[F.filter(e=>V||!e.temporary).map(t=>(0,j.jsxs)(S,{children:[(0,j.jsx)(f,{children:t.name}),(0,j.jsx)(f,{children:t.email}),(0,j.jsx)(f,{children:m(t.administrator,n)}),(0,j.jsx)(f,{children:m(t.disabled,n)}),(0,j.jsx)(f,{children:g(t.expirationTime,`date`)}),(0,j.jsx)(f,{children:(0,j.jsx)(N,{userId:t.id})}),(0,j.jsx)(f,{className:e.columnAction,padding:`none`,children:(0,j.jsx)(T,{itemId:t.id,editPath:`/settings/user`,endpoint:`users`,onReload:P,customActions:r?[W,G]:[G]})})]},t.id)),z&&(0,j.jsx)(E,{ref:F.length>0?q:null,columns:7,endAction:!0})]}),(0,j.jsx)(p,{children:(0,j.jsx)(S,{children:(0,j.jsx)(f,{colSpan:7,align:`right`,children:(0,j.jsx)(_,{control:(0,j.jsx)(c,{value:V,onChange:e=>H(e.target.checked),size:`small`}),label:n(`userTemporary`),labelPlacement:`start`})})})})]}),(0,j.jsx)(o,{editPath:`/settings/user`})]})};export{P as default};