import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,Y as n,zt as r}from"./mui-B6lh3XSP.js";import{I as i,P as a,R as o}from"./index-KVuxnkWj.js";var s=e(t(),1),c={r:[.13572138,4.6153926,-42.66032258,132.13108234,-152.94239396,59.28637943],g:[.09140261,2.19418839,4.84296658,-14.18503333,4.27729857,2.82956604],b:[.1066733,12.64194608,-60.58204836,110.36276771,-89.90310912,27.34824973]},l=(e,t)=>{let n=0;for(let r=0;r<t.length;r+=1)n+=t[r]*e**r;return Math.max(0,Math.min(1,n))},u=e=>{let t=Math.max(0,Math.min(1,e));return[Math.round(255*l(t,c.r)),Math.round(255*l(t,c.g)),Math.round(255*l(t,c.b))]},d=(e,t,n)=>{let[r,i,a]=u((e-t)/(n-t));return`rgb(${r}, ${i}, ${a})`},f=({positions:e})=>{let t=(0,s.useId)(),c=n(),l=r(t=>{let n=e?.find(()=>!0);if(n){let e=t.devices.items[n.deviceId]?.attributes;if(e){let t=e[`web.reportColor`];if(t)return t}}return null}),u=o(`mapLineWidth`,2),f=o(`mapLineOpacity`,1);return(0,s.useEffect)(()=>(i.addSource(t,{type:`geojson`,data:{type:`Feature`,geometry:{type:`LineString`,coordinates:[]}}}),i.addLayer({source:t,id:`${t}-line`,type:`line`,layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":[`get`,`color`],"line-width":[`get`,`width`],"line-opacity":[`get`,`opacity`]}}),()=>{i.getLayer(`${t}-line`)&&i.removeLayer(`${t}-line`),i.getSource(t)&&i.removeSource(t)}),[t]),(0,s.useEffect)(()=>{let n=e.map(e=>e.speed).reduce((e,t)=>Math.min(e,t),1/0),r=e.map(e=>e.speed).reduce((e,t)=>Math.max(e,t),-1/0),o=[];for(let t=0;t<e.length-1;t+=1)o.push({type:`Feature`,geometry:{type:`LineString`,coordinates:[a(e[t].longitude,e[t].latitude),a(e[t+1].longitude,e[t+1].latitude)]},properties:{color:l||d(e[t+1].speed,n,r),width:u,opacity:f}});i.getSource(t)?.setData({type:`FeatureCollection`,features:o})},[c,e,l,u,f,t]),null};export{d as n,u as r,f as t};