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{n as a}from"./MenuItem-BNgF7Xqv.js";import{r as o,t as s}from"./ReportFilter-CtusU-vs.js";import{t as c}from"./TableHead-DZPVxfXH.js";import{K as l,N as u,St as d,T as f,Y as p,lt as m,pt as h,vt as g,w as _,wt as v,xt as y}from"./index-bel1r0Sr.js";import{n as b,t as x}from"./MapView-Bhqzv-Oc.js";import{t as S}from"./MapGeofence-B_elFORD.js";import{t as C}from"./MapScale-BXKn6Q3F.js";import{t as w}from"./deviceEquality-4aERFrOn.js";import{t as T}from"./MapCamera-iXfOxITp.js";import{t as E}from"./ReportsMenu-CwjT__h7.js";import{t as D}from"./TableShimmer-CBuxG-nx.js";import{t as O}from"./ResizeHandle-Bls_OI9_.js";import{t as k}from"./MapMarkers-Dw0K9H9z.js";var A=e(t(),1),j=({name:e,coordinates:t,deviceId:i})=>{let a=(0,A.useId)(),o=n(),s=r(e=>{let t=e.devices.items[i]?.attributes;if(t){let e=t[`web.reportColor`];if(e)return e}return o.palette.geometry.main}),c=f(`mapLineWidth`,2),l=f(`mapLineOpacity`,1);return(0,A.useEffect)(()=>(b.addSource(a,{type:`geojson`,data:{type:`Feature`,geometry:{type:`LineString`,coordinates:[]}}}),b.addLayer({source:a,id:`${a}-line`,type:`line`,layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":[`get`,`color`],"line-width":[`get`,`width`],"line-opacity":[`get`,`opacity`]}}),b.addLayer({source:a,id:`${a}-title`,type:`symbol`,layout:{"text-field":`{name}`,"text-font":u(b),"text-size":12},paint:{"text-halo-color":`white`,"text-halo-width":1}}),()=>{b.getLayer(`${a}-title`)&&b.removeLayer(`${a}-title`),b.getLayer(`${a}-line`)&&b.removeLayer(`${a}-line`),b.getSource(a)&&b.removeSource(a)}),[a]),(0,A.useEffect)(()=>{b.getSource(a)?.setData({type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{name:e,color:s,width:c,opacity:l}})},[o,t,s,c,l,a,e]),null},M=i(),N=()=>{let{classes:e}=o(),t=h(),n=r(e=>e.devices.items,w([`id`,`name`])),[i,u]=(0,A.useState)([]),[f,b]=(0,A.useState)(!1),N=(0,A.useMemo)(()=>i.flatMap(e=>e.route),[i]),P=()=>i.flatMap(e=>e.events.map(t=>e.positions.find(e=>t.positionId===e.id)).filter(e=>e!=null).map(e=>({latitude:e.latitude,longitude:e.longitude}))),F=m(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)),b(!0);try{u(await(await _(`/api/reports/combined?${i.toString()}`)).json())}finally{b(!1)}},[]);return(0,M.jsx)(a,{menu:(0,M.jsx)(E,{}),breadcrumbs:[`reportTitle`,`reportCombined`],children:(0,M.jsxs)(`div`,{className:e.container,children:[!!i.length&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:e.containerMap,children:[(0,M.jsxs)(x,{children:[(0,M.jsx)(S,{}),i.map(e=>(0,M.jsx)(j,{name:n[e.deviceId].name,coordinates:e.route,deviceId:e.deviceId},e.deviceId)),(0,M.jsx)(k,{markers:P()})]}),(0,M.jsx)(C,{}),(0,M.jsx)(T,{coordinates:N})]}),(0,M.jsx)(O,{})]}),(0,M.jsxs)(`div`,{className:e.containerMain,children:[(0,M.jsx)(`div`,{className:e.header,children:(0,M.jsx)(s,{onShow:F,deviceType:`multiple`,loading:f})}),(0,M.jsxs)(v,{children:[(0,M.jsx)(c,{children:(0,M.jsxs)(g,{children:[(0,M.jsx)(y,{children:t(`sharedDevice`)}),(0,M.jsx)(y,{children:t(`positionFixTime`)}),(0,M.jsx)(y,{children:t(`sharedType`)})]})}),(0,M.jsx)(d,{children:f?(0,M.jsx)(D,{columns:3}):i.flatMap(e=>e.events.map((r,i)=>(0,M.jsxs)(g,{children:[(0,M.jsx)(y,{children:i?``:n[e.deviceId].name}),(0,M.jsx)(y,{children:l(r.eventTime,`seconds`)}),(0,M.jsx)(y,{children:t(p(`event`,r.type))})]},r.id)))})]})]})]})})};export{N as default};