import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,G as n,Nt as r}from"./mui-BgU4WrXF.js";import{T as i}from"./index-bel1r0Sr.js";import{n as a}from"./MapView-Bhqzv-Oc.js";var o=e(t(),1),s={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]},c=(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))},l=e=>{let t=Math.max(0,Math.min(1,e));return[Math.round(255*c(t,s.r)),Math.round(255*c(t,s.g)),Math.round(255*c(t,s.b))]},u=(e,t,n)=>{let[r,i,a]=l((e-t)/(n-t));return`rgb(${r}, ${i}, ${a})`},d=({positions:e})=>{let t=(0,o.useId)(),s=n(),c=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}),l=i(`mapLineWidth`,2),d=i(`mapLineOpacity`,1);return(0,o.useEffect)(()=>(a.addSource(t,{type:`geojson`,data:{type:`Feature`,geometry:{type:`LineString`,coordinates:[]}}}),a.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`]}}),()=>{a.getLayer(`${t}-line`)&&a.removeLayer(`${t}-line`),a.getSource(t)&&a.removeSource(t)}),[t]),(0,o.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),i=[];for(let t=0;t<e.length-1;t+=1)i.push({type:`Feature`,geometry:{type:`LineString`,coordinates:[[e[t].longitude,e[t].latitude],[e[t+1].longitude,e[t+1].latitude]]},properties:{color:c||u(e[t+1].speed,n,r),width:l,opacity:d}});a.getSource(t)?.setData({type:`FeatureCollection`,features:i})},[s,e,c,l,d,t]),null};export{u as n,l as r,d as t};