import{LngLat as e}from"maplibre-gl";import{InputType as t,OrMwcInput as n}from"@openremote/or-mwc-components/or-mwc-input";export const CoordinatesRegexPattern="^[ ]*(?:Lat: )?(-?\\d+\\.?\\d*)[, ]+(?:Lng: )?(-?\\d+\\.?\\d*)[ ]*$";export function getCoordinatesInputKeyHandler(t){return n=>{if("Enter"===n.code||"NumpadEnter"===n.code){let o=n.target.value,r=o?{}:void 0;if(o){let t=o.split(/[ ,]/).filter(e=>!!e);2===t.length&&(r=new e(Number.parseFloat(t[0]),Number.parseFloat(t[1])))}t(r)}}}export class CoordinatesControl{constructor(e=!1,t){this._readonly=!1,this._readonly=e,this._valueChangedHandler=t}onAdd(e){this.map=e;let o=document.createElement("div");o.classList.add("maplibregl-ctrl"),o.classList.add("maplibregl-ctrl-group");let r=new n;return r.type=t.TEXT,r.outlined=!0,r.compact=!0,r.readonly=this._readonly,r.icon="crosshairs-gps",r.value=this._value,r.pattern="^[ ]*(?:Lat: )?(-?\\d+\\.?\\d*)[, ]+(?:Lng: )?(-?\\d+\\.?\\d*)[ ]*$",r.onkeyup=getCoordinatesInputKeyHandler(this._valueChangedHandler),o.appendChild(r),this.elem=o,this.input=r,o}onRemove(e){this.map=void 0,this.elem=void 0}set readonly(e){this._readonly=e,this.input&&(this.input.readonly=e)}set value(e){this._value=e,this.input&&(this.input.value=e)}}