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{d as a}from"./IconButton-BEBOUWhl.js";import{n as o}from"./MenuItem-HQNtf0LG.js";import{n as s,r as c,t as l}from"./ReportFilter-DWQ_hjet.js";import{t as u}from"./TableHead-_KJlbpnj.js";import{At as d,Dt as f,Ot as p,Q as m,St as h,Y as g,ht as _,mt as v,w as y,wt as b,yt as x}from"./index-KVuxnkWj.js";import{t as S}from"./SelectField-9K8NpSQG.js";import{t as C}from"./deviceEquality-4aERFrOn.js";import{t as w}from"./ReportsMenu-XWwKkI0p.js";import{t as T}from"./ColumnSelect-BAx72xpb.js";import{t as E}from"./TableShimmer-f7Cf4NTV.js";import{t as D}from"./exportExcel-D5CrW9S1.js";var O=e(t(),1),k=r(),A=[[`geofenceId`,`sharedGeofence`],[`startTime`,`reportStartTime`],[`endTime`,`reportEndTime`],[`duration`,`reportDuration`]],j=new Map(A),M=()=>{let{classes:e}=c(),t=x(),r=n(),[M,N]=a(),P=(0,O.useMemo)(()=>M.getAll(`geofenceId`).map(Number),[M]),F=i(e=>e.devices.items,C([`id`,`name`])),I=i(e=>e.geofences.items),[L,R]=h(`geofenceColumns`,[`geofenceId`,`startTime`,`endTime`]),[z,B]=(0,O.useState)([]),[V,H]=(0,O.useState)(!1),U=_(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=v(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,r)}),G=(e,n)=>{switch(n){case`geofenceId`:return I[e.geofenceId]?.name||e.geofenceId;case`startTime`:case`endTime`:return m(e[n],`minutes`);case`duration`:return g(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)(d,{children:[(0,k.jsx)(u,{children:(0,k.jsxs)(b,{children:[(0,k.jsx)(f,{children:t(`sharedDevice`)}),L.map(e=>(0,k.jsx)(f,{children:t(j.get(e))},e))]})}),(0,k.jsx)(p,{children:V?(0,k.jsx)(E,{columns:L.length+1}):z.map(e=>(0,k.jsxs)(b,{children:[(0,k.jsx)(f,{children:F[e.deviceId]?.name||e.deviceId}),L.map(t=>(0,k.jsx)(f,{children:G(e,t)},t))]},`${e.deviceId}_${e.geofenceId}_${e.startTime}_${e.endTime}`))})]})]})};export{M as default};