import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,G as n,Nt as r,vt as i}from"./mui-BgU4WrXF.js";import{l as a}from"./IconButton-oialqkv3.js";import{n as ee}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{E as u,Ft as d,G as te,K as f,Mt as p,O as m,R as h,St as g,Ut as _,bt as v,c as y,ct as b,dt as x,gt as S,k as C,pt as w,st as T,vt as E,w as D,wt as O,xt as k}from"./index-bel1r0Sr.js";import{t as A}from"./CollectionActions-Be6ZPRyC.js";import{t as j}from"./TableShimmer-CBuxG-nx.js";import{t as M}from"./exportExcel-DStci2wm.js";import{n as N,t as P}from"./useSettingsStyles-Bugi6oTj.js";import{t as F}from"./Link-CzZvBT6w.js";var I=e(t(),1),L=i(),R=({deviceId:e})=>{let t=w(),[n,r]=(0,I.useState)(),i=b(async()=>{r(await(await D(`/api/users?${new URLSearchParams({deviceId:e}).toString()}`)).json())});return n?n.map(e=>e.name).join(`, `):(0,L.jsx)(p,{href:`#`,onClick:i,children:t(`reportShow`)})},z=()=>{let{classes:e}=P(),t=n(),i=a(),p=w(),b=r(e=>e.groups.items),z=C(),B=m(),V=u(`coordinateFormat`),H=r(e=>e.session.positions),[U,W]=(0,I.useReducer)(e=>e+1,0),[G,K]=(0,I.useState)([]),[q,J]=(0,I.useState)(``),[Y,X]=S(`showAllDevices`,!1),[Z,Q]=(0,I.useState)(!0),$=(0,I.useCallback)(async(e,t)=>{let n=new URLSearchParams({all:Y,limit:50,offset:e});q&&n.append(`keyword`,q);let r=await(await D(`/api/devices?${n.toString()}`,{signal:t})).json();K(t=>e?[...t,...r]:r),Q(r.length>=50)},[q,Y]),ne=x(()=>$(G.length));T(async({signal:e})=>{K([]),await $(0,e)},[U,$]);let re=async()=>{let e=G.map(e=>({[p(`sharedName`)]:e.name,[p(`deviceIdentifier`)]:e.uniqueId,[p(`groupParent`)]:e.groupId?b[e.groupId]?.name:null,[p(`sharedPhone`)]:e.phone,[p(`deviceModel`)]:e.model,[p(`deviceContact`)]:e.contact,[p(`userExpirationTime`)]:f(e.expirationTime,`date`),[p(`deviceStatus`)]:te(e.status,p),[p(`deviceLastUpdate`)]:f(e.lastUpdate,`minutes`),[p(`positionAddress`)]:H[e.id]?h(H[e.id],V):``})),n=new Map;n.set(p(`deviceTitle`),e),await M(p(`deviceTitle`),`devices.xlsx`,n,t)},ie={key:`connections`,title:p(`sharedConnections`),icon:(0,L.jsx)(F,{fontSize:`small`}),handler:e=>i(`/settings/device/${e}/connections`)};return(0,L.jsxs)(ee,{menu:(0,L.jsx)(N,{}),breadcrumbs:[`settingsTitle`,`deviceTitle`],children:[(0,L.jsx)(s,{keyword:q,setKeyword:J}),(0,L.jsxs)(O,{className:e.table,children:[(0,L.jsx)(l,{children:(0,L.jsxs)(E,{children:[(0,L.jsx)(k,{children:p(`sharedName`)}),(0,L.jsx)(k,{children:p(`deviceIdentifier`)}),(0,L.jsx)(k,{children:p(`groupParent`)}),(0,L.jsx)(k,{children:p(`sharedPhone`)}),(0,L.jsx)(k,{children:p(`deviceModel`)}),(0,L.jsx)(k,{children:p(`deviceContact`)}),(0,L.jsx)(k,{children:p(`userExpirationTime`)}),(0,L.jsx)(k,{children:p(`positionAddress`)}),z&&(0,L.jsx)(k,{children:p(`settingsUsers`)}),(0,L.jsx)(k,{className:e.columnAction})]})}),(0,L.jsxs)(g,{children:[G.map(t=>(0,L.jsxs)(E,{children:[(0,L.jsx)(k,{children:t.name}),(0,L.jsx)(k,{children:t.uniqueId}),(0,L.jsx)(k,{children:t.groupId?b[t.groupId]?.name:null}),(0,L.jsx)(k,{children:t.phone}),(0,L.jsx)(k,{children:t.model}),(0,L.jsx)(k,{children:t.contact}),(0,L.jsx)(k,{children:f(t.expirationTime,`date`)}),(0,L.jsx)(k,{children:H[t.id]&&(0,L.jsx)(y,{latitude:H[t.id].latitude,longitude:H[t.id].longitude,originalAddress:H[t.id]?.address})}),z&&(0,L.jsx)(k,{children:(0,L.jsx)(R,{deviceId:t.id})}),(0,L.jsx)(k,{className:e.columnAction,padding:`none`,children:(0,L.jsx)(A,{itemId:t.id,editPath:`/settings/device`,endpoint:`devices`,onReload:W,customActions:[ie],readonly:B})})]},t.id)),Z&&(0,L.jsx)(j,{ref:G.length>0?ne:null,columns:z?9:8,endAction:!0})]}),(0,L.jsx)(v,{children:(0,L.jsxs)(E,{children:[(0,L.jsx)(k,{children:(0,L.jsx)(_,{onClick:re,variant:`text`,children:p(`reportExport`)})}),(0,L.jsx)(k,{colSpan:z?9:8,align:`right`,children:(0,L.jsx)(d,{control:(0,L.jsx)(c,{checked:Y,onChange:e=>X(e.target.checked),size:`small`}),label:p(`notificationAlways`),labelPlacement:`start`,disabled:!z})})]})})]}),(0,L.jsx)(o,{editPath:`/settings/device`})]})};export{z as default};