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{d as a}from"./IconButton-oialqkv3.js";import{n as o}from"./MenuItem-BNgF7Xqv.js";import{n as s,r as c,t as l}from"./ReportFilter-CtusU-vs.js";import{t as u}from"./TableHead-DZPVxfXH.js";import{K as d,St as f,U as p,ct as m,gt as h,lt as g,pt as _,vt as v,w as y,wt as b,xt as x}from"./index-bel1r0Sr.js";import{t as S}from"./SelectField-Bcp-L6wk.js";import{t as C}from"./deviceEquality-4aERFrOn.js";import{t as w}from"./ReportsMenu-CwjT__h7.js";import{t as T}from"./ColumnSelect-CwYQdTe9.js";import{t as E}from"./TableShimmer-CBuxG-nx.js";import{t as D}from"./exportExcel-DStci2wm.js";var O=e(t(),1),k=i(),A=[[`geofenceId`,`sharedGeofence`],[`startTime`,`reportStartTime`],[`endTime`,`reportEndTime`],[`duration`,`reportDuration`]],j=new Map(A),M=()=>{let{classes:e}=c(),t=_(),i=n(),[M,N]=a(),P=(0,O.useMemo)(()=>M.getAll(`geofenceId`).map(Number),[M]),F=r(e=>e.devices.items,C([`id`,`name`])),I=r(e=>e.geofences.items),[L,R]=h(`geofenceColumns`,[`geofenceId`,`startTime`,`endTime`]),[z,B]=(0,O.useState)([]),[V,H]=(0,O.useState)(!1),U=g(async({deviceIds:e,groupIds:t,from:n,to:r})=>{let i=new URLSearchParams({from:n,to:r});e.forEach(e=>i.append(`deviceId`,e)),t.forEach(e=>i.append(`groupId`,e)),P.forEach(e=>i.append(`geofenceId`,e)),H(!0);try{B(await(await y(`/api/reports/geofences?${i.toString()}`,{headers:{Accept:`application/json`}})).json())}finally{H(!1)}},[P]),W=m(async()=>{let e=new Map;z.forEach(n=>{let r=F[n.deviceId].name;e.has(r)||e.set(r,[]);let i={};L.forEach(e=>{let r=t(j.get(e));i[r]=G(n,e)}),e.get(r).push(i)}),await D(t(`sharedGeofences`),`geofences.xlsx`,e,i)}),G=(e,n)=>{switch(n){case`geofenceId`:return I[e.geofenceId]?.name||e.geofenceId;case`startTime`:case`endTime`:return d(e[n],`minutes`);case`duration`:return p(Date.parse(e.endTime)-Date.parse(e.startTime),t);default:return e[n]}};return(0,k.jsxs)(o,{menu:(0,k.jsx)(w,{}),breadcrumbs:[`reportTitle`,`sharedGeofences`],children:[(0,k.jsx)(`div`,{className:e.header,children:(0,k.jsxs)(l,{onShow:U,onExport:W,deviceType:`multiple`,loading:V,formats:[`xlsx`],children:[(0,k.jsx)(`div`,{className:e.filterItem,children:(0,k.jsx)(S,{label:t(`sharedGeofences`),value:P,onChange:e=>s(M,N,`geofenceId`,e.target.value),endpoint:`/api/geofences`,multiple:!0,singleLine:!0,fullWidth:!0})}),(0,k.jsx)(T,{columns:L,setColumns:R,columnsArray:A})]})}),(0,k.jsxs)(b,{children:[(0,k.jsx)(u,{children:(0,k.jsxs)(v,{children:[(0,k.jsx)(x,{children:t(`sharedDevice`)}),L.map(e=>(0,k.jsx)(x,{children:t(j.get(e))},e))]})}),(0,k.jsx)(f,{children:V?(0,k.jsx)(E,{columns:L.length+1}):z.map(e=>(0,k.jsxs)(v,{children:[(0,k.jsx)(x,{children:F[e.deviceId]?.name||e.deviceId}),L.map(t=>(0,k.jsx)(x,{children:G(e,t)},t))]},`${e.deviceId}_${e.geofenceId}_${e.startTime}_${e.endTime}`))})]})]})};export{M as default};