import{LngLat as t,LngLatBounds as e}from"maplibre-gl";import{AssetModelUtil as n}from"@openremote/model";export function getLngLat(e){if(e){if(e instanceof t)return e;if(e.lat)return e.lon?{lng:e.lon,lat:e.lat}:{lng:e.lng,lat:e.lat};if(Array.isArray(e))return{lng:e[0],lat:e[1]};if(e.coordinates&&Array.isArray(e.coordinates)&&e.coordinates.length>=2)return getLngLat(e.coordinates);if(e.attributes){let t=e.attributes.location;return t&&t.value?getLngLat(t.value):void 0}if(e.value)return getLngLat(e.value)}}export function getGeoJSONPoint(t){if(t)return Array.isArray(t)?{type:"Point",coordinates:t}:{type:"Point",coordinates:[t.hasOwnProperty("lng")?t.lng:t.lon,t.lat]}}export function getLngLatBounds(t){if(t){if(t instanceof e)return t;if(2===t.length){let n=getLngLat(t[0]),r=getLngLat(t[1]);if(n&&r)return new e(n,r)}if(4===t.length)return new e([t[0],t[1],t[2],t[3]])}}export function getLatLngBounds(t){let e=getLngLatBounds(t);if(e)return L.latLngBounds(e.getNorthEast(),e.getSouthWest())}export function getMarkerIconAndColorFromAssetType(t,e){if(!t)return;let r="string"==typeof t?n.getAssetDescriptor(t):t,o=r&&r.icon?r.icon:"help-circle",i=r&&r.colour?r.colour:void 0;if(e&&e.markerConfig){let t=e.markerConfig,n=e.currentValue;if("range"===t.type&&t.ranges&&"number"==typeof n){let e=t.ranges;i=(e.sort((t,e)=>e.min-t.min).find(t=>n>=t.min)||e.reduce((t,e)=>e.min>t.min?t:e)).colour||void 0}else"boolean"===t.type?i=t[!!n+""]:"string"===t.type&&(i=t[n+""])}return{color:i,icon:o}}