import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,Y as n,wt as r,zt as i}from"./mui-B6lh3XSP.js";import{l as a}from"./IconButton-BEBOUWhl.js";import{n as ee}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,E as p,Et as m,Ot as h,Q as g,St as _,W as v,Wt as y,Z as b,_t as te,c as x,en as S,mt as C,pt as w,w as T,wt as E,yt as D,z as O,zt as k}from"./index-KVuxnkWj.js";import{t as A}from"./CollectionActions-CDxOJIb6.js";import{t as j}from"./TableShimmer-f7Cf4NTV.js";import{t as M}from"./exportExcel-D5CrW9S1.js";import{n as N,t as P}from"./useSettingsStyles-X3caKosH.js";import{t as F}from"./Link-C46sYcuF.js";var I=e(t(),1),L=r(),R=({deviceId:e})=>{let t=D(),[n,r]=(0,I.useState)(),i=C(async()=>{r(await(await T(`/api/users?${new URLSearchParams({deviceId:e}).toString()}`)).json())});return n?n.map(e=>e.name).join(`, `):(0,L.jsx)(k,{href:`#`,onClick:i,children:t(`reportShow`)})},z=()=>{let{classes:e}=P(),t=n(),r=a(),C=D(),k=i(e=>e.groups.items),z=d(),B=p(),V=O(`coordinateFormat`),H=i(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]=_(`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 T(`/api/devices?${n.toString()}`,{signal:t})).json();K(t=>e?[...t,...r]:r),Q(r.length>=50)},[q,Y]),ne=te(()=>$(G.length));w(async({signal:e})=>{K([]),await $(0,e)},[U,$]);let re=async()=>{let e=G.map(e=>({[C(`sharedName`)]:e.name,[C(`deviceIdentifier`)]:e.uniqueId,[C(`groupParent`)]:e.groupId?k[e.groupId]?.name:null,[C(`sharedPhone`)]:e.phone,[C(`deviceModel`)]:e.model,[C(`deviceContact`)]:e.contact,[C(`userExpirationTime`)]:g(e.expirationTime,`date`),[C(`deviceStatus`)]:b(e.status,C),[C(`deviceLastUpdate`)]:g(e.lastUpdate,`minutes`),[C(`positionAddress`)]:H[e.id]?v(H[e.id],V):``})),n=new Map;n.set(C(`deviceTitle`),e),await M(C(`deviceTitle`),`devices.xlsx`,n,t)},ie={key:`connections`,title:C(`sharedConnections`),icon:(0,L.jsx)(F,{fontSize:`small`}),handler:e=>r(`/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)(u,{className:e.table,children:[(0,L.jsx)(l,{children:(0,L.jsxs)(E,{children:[(0,L.jsx)(f,{children:C(`sharedName`)}),(0,L.jsx)(f,{children:C(`deviceIdentifier`)}),(0,L.jsx)(f,{children:C(`groupParent`)}),(0,L.jsx)(f,{children:C(`sharedPhone`)}),(0,L.jsx)(f,{children:C(`deviceModel`)}),(0,L.jsx)(f,{children:C(`deviceContact`)}),(0,L.jsx)(f,{children:C(`userExpirationTime`)}),(0,L.jsx)(f,{children:C(`positionAddress`)}),z&&(0,L.jsx)(f,{children:C(`settingsUsers`)}),(0,L.jsx)(f,{className:e.columnAction})]})}),(0,L.jsxs)(h,{children:[G.map(t=>(0,L.jsxs)(E,{children:[(0,L.jsx)(f,{children:t.name}),(0,L.jsx)(f,{children:t.uniqueId}),(0,L.jsx)(f,{children:t.groupId?k[t.groupId]?.name:null}),(0,L.jsx)(f,{children:t.phone}),(0,L.jsx)(f,{children:t.model}),(0,L.jsx)(f,{children:t.contact}),(0,L.jsx)(f,{children:g(t.expirationTime,`date`)}),(0,L.jsx)(f,{children:H[t.id]&&(0,L.jsx)(x,{latitude:H[t.id].latitude,longitude:H[t.id].longitude,originalAddress:H[t.id]?.address})}),z&&(0,L.jsx)(f,{children:(0,L.jsx)(R,{deviceId:t.id})}),(0,L.jsx)(f,{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)(m,{children:(0,L.jsxs)(E,{children:[(0,L.jsx)(f,{children:(0,L.jsx)(S,{onClick:re,variant:`text`,children:C(`reportExport`)})}),(0,L.jsx)(f,{colSpan:z?9:8,align:`right`,children:(0,L.jsx)(y,{control:(0,L.jsx)(c,{checked:Y,onChange:e=>X(e.target.checked),size:`small`}),label:C(`notificationAlways`),labelPlacement:`start`,disabled:!z})})]})})]}),(0,L.jsx)(o,{editPath:`/settings/device`})]})};export{z as default};