import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,L as n,vt as r}from"./mui-BgU4WrXF.js";import{l as i}from"./IconButton-oialqkv3.js";import{n as a}from"./MenuItem-BNgF7Xqv.js";import{n as o,t as s}from"./SearchHeader-CjrB_H_O.js";import{t as c}from"./Switch-BoT5jv3s.js";import{t as l}from"./TableHead-DZPVxfXH.js";import{Ft as u,K as d,Mt as f,St as p,bt as m,ct as h,dt as g,k as _,pt as v,st as y,vt as b,w as x,wt as S,xt as C,z as w}from"./index-bel1r0Sr.js";import{t as T}from"./CollectionActions-Be6ZPRyC.js";import{t as E}from"./TableShimmer-CBuxG-nx.js";import{n as D,t as O}from"./useSettingsStyles-Bugi6oTj.js";import{t as k}from"./Link-CzZvBT6w.js";var A=e(t(),1),j=r(),M=n((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=v(),[n,r]=(0,A.useState)(),i=h(async()=>{r(await(await x(`/api/devices?${new URLSearchParams({userId:e}).toString()}`)).json())});return n?n.length:(0,j.jsx)(f,{href:`#`,onClick:i,children:t(`reportShow`)})},P=()=>{let{classes:e}=O(),t=i(),n=v(),r=_(),[f,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=h(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=g(()=>K(F.length));return y(async({signal:e})=>{I([]),await K(0,e)},[f,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)(S,{className:e.table,children:[(0,j.jsx)(l,{children:(0,j.jsxs)(b,{children:[(0,j.jsx)(C,{children:n(`sharedName`)}),(0,j.jsx)(C,{children:n(`userEmail`)}),(0,j.jsx)(C,{children:n(`userAdmin`)}),(0,j.jsx)(C,{children:n(`sharedDisabled`)}),(0,j.jsx)(C,{children:n(`userExpirationTime`)}),(0,j.jsx)(C,{children:n(`deviceTitle`)}),(0,j.jsx)(C,{className:e.columnAction})]})}),(0,j.jsxs)(p,{children:[F.filter(e=>V||!e.temporary).map(t=>(0,j.jsxs)(b,{children:[(0,j.jsx)(C,{children:t.name}),(0,j.jsx)(C,{children:t.email}),(0,j.jsx)(C,{children:w(t.administrator,n)}),(0,j.jsx)(C,{children:w(t.disabled,n)}),(0,j.jsx)(C,{children:d(t.expirationTime,`date`)}),(0,j.jsx)(C,{children:(0,j.jsx)(N,{userId:t.id})}),(0,j.jsx)(C,{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)(m,{children:(0,j.jsx)(b,{children:(0,j.jsx)(C,{colSpan:7,align:`right`,children:(0,j.jsx)(u,{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};