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{n as a}from"./MenuItem-HQNtf0LG.js";import{r as o,t as s}from"./ReportFilter-DWQ_hjet.js";import{t as c}from"./TableHead-_KJlbpnj.js";import{A as l,At as u,Dt as d,F as f,I as p,Ot as m,P as h,Q as g,R as _,ht as v,tt as y,w as b,wt as x,yt as S}from"./index-KVuxnkWj.js";import{t as C}from"./MapGeofence-Bl8PxdWQ.js";import{t as w}from"./MapScale-Bi_SBcLe.js";import{t as T}from"./deviceEquality-4aERFrOn.js";import{t as E}from"./MapCamera-C0XDEMbg.js";import{t as D}from"./ReportsMenu-XWwKkI0p.js";import{t as O}from"./TableShimmer-f7Cf4NTV.js";import{t as k}from"./ResizeHandle-Be-cOoy0.js";import{t as A}from"./MapMarkers-D-82xaXu.js";var j=e(t(),1),M=({name:e,coordinates:t,deviceId:r})=>{let a=(0,j.useId)(),o=n(),s=i(e=>{let t=e.devices.items[r]?.attributes;if(t){let e=t[`web.reportColor`];if(e)return e}return o.palette.geometry.main}),c=_(`mapLineWidth`,2),u=_(`mapLineOpacity`,1);return(0,j.useEffect)(()=>(p.addSource(a,{type:`geojson`,data:{type:`Feature`,geometry:{type:`LineString`,coordinates:[]}}}),p.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`]}}),p.addLayer({source:a,id:`${a}-title`,type:`symbol`,layout:{"text-field":`{name}`,"text-font":l(p),"text-size":12},paint:{"text-halo-color":`white`,"text-halo-width":1}}),()=>{p.getLayer(`${a}-title`)&&p.removeLayer(`${a}-title`),p.getLayer(`${a}-line`)&&p.removeLayer(`${a}-line`),p.getSource(a)&&p.removeSource(a)}),[a]),(0,j.useEffect)(()=>{p.getSource(a)?.setData({type:`Feature`,geometry:{type:`LineString`,coordinates:t.map(([e,t])=>h(e,t))},properties:{name:e,color:s,width:c,opacity:u}})},[o,t,s,c,u,a,e]),null},N=r(),P=()=>{let{classes:e}=o(),t=S(),n=i(e=>e.devices.items,T([`id`,`name`])),[r,l]=(0,j.useState)([]),[p,h]=(0,j.useState)(!1),_=(0,j.useMemo)(()=>r.flatMap(e=>e.route),[r]),P=()=>r.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=v(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)),h(!0);try{l(await(await b(`/api/reports/combined?${i.toString()}`)).json())}finally{h(!1)}},[]);return(0,N.jsx)(a,{menu:(0,N.jsx)(D,{}),breadcrumbs:[`reportTitle`,`reportCombined`],children:(0,N.jsxs)(`div`,{className:e.container,children:[!!r.length&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:e.containerMap,children:[(0,N.jsxs)(f,{children:[(0,N.jsx)(C,{}),r.map(e=>(0,N.jsx)(M,{name:n[e.deviceId].name,coordinates:e.route,deviceId:e.deviceId},e.deviceId)),(0,N.jsx)(A,{markers:P()})]}),(0,N.jsx)(w,{}),(0,N.jsx)(E,{coordinates:_})]}),(0,N.jsx)(k,{})]}),(0,N.jsxs)(`div`,{className:e.containerMain,children:[(0,N.jsx)(`div`,{className:e.header,children:(0,N.jsx)(s,{onShow:F,deviceType:`multiple`,loading:p})}),(0,N.jsxs)(u,{children:[(0,N.jsx)(c,{children:(0,N.jsxs)(x,{children:[(0,N.jsx)(d,{children:t(`sharedDevice`)}),(0,N.jsx)(d,{children:t(`positionFixTime`)}),(0,N.jsx)(d,{children:t(`sharedType`)})]})}),(0,N.jsx)(m,{children:p?(0,N.jsx)(O,{columns:3}):r.flatMap(e=>e.events.map((r,i)=>(0,N.jsxs)(x,{children:[(0,N.jsx)(d,{children:i?``:n[e.deviceId].name}),(0,N.jsx)(d,{children:g(r.eventTime,`seconds`)}),(0,N.jsx)(d,{children:t(y(`event`,r.type))})]},r.id)))})]})]})]})})};export{P as default};