var __decorate=this&&this.__decorate||function(e,t,o,r){var a,s=arguments.length,n=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(n=(s<3?a(n):s>3?a(t,o,n):a(t,o))||n);return s>3&&n&&Object.defineProperty(t,o,n),n};import e from"@openremote/core";import{html as t,LitElement as o}from"lit";import{customElement as r,property as a,query as s}from"lit/decorators.js";import{LngLat as n,GeolocateControl as i}from"maplibre-gl";import{style as p}from"./style";import{OrMapMarker as l,OrMapMarkerChangedEvent as d}from"./markers/or-map-marker";import"./markers/or-map-marker-asset";import*as m from"./util";import{InputType as c}from"@openremote/or-mwc-components/or-mwc-input";import{OrMwcDialog as u,showDialog as h}from"@openremote/or-mwc-components/or-mwc-dialog";import{getMarkerIconAndColorFromAssetType as v}from"./util";import{i18next as g}from"@openremote/or-translate";import A from"lodash.debounce";import{CoordinatesControl as f,CoordinatesRegexPattern as M,getCoordinatesInputKeyHandler as y}from"./controls/coordinates";import{AssetMap as b}from"./asset-map";import{CenterControl as O}from"./controls/center";export*from"./markers/or-map-marker";export*from"./markers/or-map-marker-asset";export*from"./markers/or-cluster-marker";export*from"./or-map-asset-card";export*from"./or-map-legend";export class OrMapLoadedEvent extends CustomEvent{constructor(){super(OrMapLoadedEvent.NAME,{bubbles:!0,composed:!0})}}OrMapLoadedEvent.NAME="or-map-loaded";export class OrMapClickedEvent extends CustomEvent{constructor(e,t=!1){super(OrMapClickedEvent.NAME,{detail:{doubleClick:t,lngLat:e},bubbles:!0,composed:!0})}}OrMapClickedEvent.NAME="or-map-clicked";export class OrMapLongPressEvent extends CustomEvent{constructor(e){super(OrMapLongPressEvent.NAME,{detail:{doubleClick:!1,lngLat:e},bubbles:!0,composed:!0})}}OrMapLongPressEvent.NAME="or-map-long-press";export class OrMapGeocoderChangeEvent extends CustomEvent{constructor(e){super(OrMapGeocoderChangeEvent.NAME,{detail:{geocode:e},bubbles:!0,composed:!0})}}OrMapGeocoderChangeEvent.NAME="or-map-geocoder-change";export class OrMapMarkersChangedEvent extends CustomEvent{constructor(e){super(OrMapMarkersChangedEvent.NAME,{detail:e,bubbles:!0,composed:!0})}}OrMapMarkersChangedEvent.NAME="or-map-markers-changed";export const geoJsonPointInputTemplateProvider=(e,o,r,a,s,p)=>{let l,d=!!(p&&p.disabled),A=!!(p&&p.readonly),b=!!(p&&p.compact),w=!!(p&&p.comfortable),C=new O,E=e=>{s&&(void 0!==e?s({value:e?m.getGeoJSONPoint(e):null}):s(void 0))},_=new f(d,E);return{templateFunction:(o,r,a,s,p,f)=>{let O,k;o&&(O=(l=m.getLngLat(o))?Object.values(l):void 0);let x=O?O.join(", "):void 0;C.pos=l||void 0,_.readonly=d||A||s||a,_.value=x;let z=v(e),B=e=>{if(!A&&!d)if(l=e?m.getLngLat(e):null,k){let e=k.shadowRoot.getElementById("geo-json-point-marker");e.lng=l?l.lng:void 0,e.lat=l?l.lat:void 0,_.value=(O=l?Object.values(l):void 0)?O.join(", "):void 0}else E(l)},j=[[C,"bottom-left"],[_,"top-right"]];if(!A){let e=new i({positionOptions:{enableHighAccuracy:!0},showAccuracyCircle:!1,showUserLocation:!1});e.on("geolocate",e=>{B(new n(e.coords.longitude,e.coords.latitude))}),e.on("outofmaxbounds",e=>{B(new n(e.coords.longitude,e.coords.latitude))}),j.push([e,"bottom-left"])}let L=t`
            <or-map id="geo-json-point-map" class="or-map" @or-map-long-press="${e=>{B(e.detail.lngLat)}}" .center="${O}" .controls="${j}" .showGeoCodingControl=${!A}>
                <or-map-marker id="geo-json-point-marker" active .lng="${l?l.lng:void 0}" .lat="${l?l.lat:void 0}" .icon="${z?z.icon:void 0}" .activeColor="${z?"#"+z.color:void 0}" .colour="${z?"#"+z.color:void 0}"></or-map-marker>
            </or-map>
            <span class="long-press-msg">${g.t("longPressSetLoc")}</span>
        `;if(b){let e=L;L=t`
                <style>
                    #geo-json-point-input-compact-wrapper {
                        display: table-cell;
                    }
                    #geo-json-point-input-compact-wrapper > * {
                        vertical-align: middle;
                    }
                </style>
                <div id="geo-json-point-input-compact-wrapper">
                    <or-mwc-input style="width: auto;" .comfortable="${w}" .type="${c.TEXT}" .value="${x}" .pattern="${M}" @keyup="${e=>y(E)(e)}"></or-mwc-input>
                    <or-mwc-input style="width: auto;" .type="${c.BUTTON}" compact icon="crosshairs-gps" @or-mwc-input-changed="${()=>{k=h(new u().setContent(e).setStyles(t`
                            <style>
                                .dialog-container {
                                    flex-direction: column !important;
                                }
                                .dialog-container .long-press-msg {
                                    display: block;
                                    text-align: center;
                                }
                                or-map {
                                    width: 600px !important;
                                    min-height: 600px !important;
                                }
                            </style>
                        `).setActions([{actionName:"none",content:"none",action:()=>{B(null),E(l)}},{actionName:"ok",content:"ok",action:()=>{E(l)}},{default:!0,actionName:"cancel",content:"cancel"}]))}}"></or-mwc-input>
                </div>
            `}return L},supportsHelperText:!1,supportsLabel:!1,supportsSendButton:!1,validator:()=>!l||void 0!==l.lat&&null!==l.lat&&void 0!==l.lng&&null!==l.lng}};let OrMap=class extends o{constructor(){super(),this.showGeoCodingControl=!1,this.showBoundaryBoxControl=!1,this.useZoomControl=!0,this.showGeoJson=!0,this.boundary=[],this._loaded=!1,this.addEventListener(d.NAME,this._onMarkerChangedEvent)}addAsset(e){var t;null==(t=this._map)||t.addAsset(e)}addAssets(e){var t;null==(t=this._map)||t.addAssets(e)}updateAttribute(e){var t;null==(t=this._map)||t.updateAttribute(e)}removeAssets(e){var t;null==(t=this._map)||t.removeAssets(e)}removeAllAssets(){var e;null==(e=this._map)||e.removeAllAssets()}firstUpdated(t){super.firstUpdated(t),e.ready&&this.loadMap()}disconnectedCallback(){var e;super.disconnectedCallback(),this._resizeObserver&&this._resizeObserver.disconnect(),null==(e=this._map)||e.unload()}render(){return t`
            <div id="container">
                <div id="map"></div>
                <slot></slot>
                <a id="openremote" href="https://openremote.io/" target="_blank">
                    <img src="data:image/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ImbJn0RyWC+1af1Iv6ukcbf+aIRKDR3b5ipVCiy+PenaupWRsSfzCWim0ftUmdiqrJwWLpbmk3196UfXG0X6NKIWKDXva0I0UQZT2nRaDfc/mhgCj0PS9ImZzefbg5fliIvuTA++/0ZaYDTDqqpzhn6lHoW36iSuLHnslfCiBqdMBGDI6/0LUhfkgGiWFbC29c+epRaJMX3YJuD+R75l15wG4DaKh5dsPJsj0GXLaawavkWY/MyUcU/JOPHCkK7fAjNZiIf/PeX/vWx1814muF0Y/EKWs95mFVuKhgX352EYAoY5vnNSDRF/9p/MgHfQ2dldNIqbPeJm2aBBix20vzg26RpUUpLfb43FxZU4YMmEJGoxXKQeIfCg4uzMkrTDVitZ0ecst1B05i0Cv26Vk8H68JjFKabXa/Zkul5w5Lxp120EHdlyu/AQCiQI1P+YxaGcwY1+20kasnM/wXCa5/Ik1hKTEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDgtMjBUMTU6MTc6NTUrMDA6MDCwJSdSAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTA4LTIwVDE1OjE3OjU1KzAwOjAwwXif7gAAAABJRU5ErkJggg==" />
                </a>
            </div>
        `}updated(e){var t;super.updated(e),(e.has("center")||e.has("zoom"))&&this.flyTo(this.center,this.zoom),e.has("boundary")&&this.showBoundaryBoxControl&&(null==(t=this._map)||t.createBoundaryBox(this.boundary))}refresh(){this._map&&this._map.loadViewSettings().then(()=>{this._map&&(this._map.setCenter(),this._map.flyTo())})}loadMap(){this._loaded||(this._mapContainer&&this._slotElement&&(this._map=new b(this.shadowRoot,this._mapContainer,this.showGeoCodingControl,this.showBoundaryBoxControl,this.useZoomControl,this.showGeoJson,this.cluster).setCenter(this.center).setZoom(this.zoom).setControls(this.controls).setGeoJson(this.geoJson),this._map.build().then(()=>{var e,t;null==(e=this._resizeObserver)||e.disconnect(),this._resizeObserver=new ResizeObserver(A(()=>{this.resize()},200));let o=null==(t=this._mapContainer)?void 0:t.parentElement;o&&this._resizeObserver.observe(o),this._slotElement.assignedNodes({flatten:!0}).forEach(e=>{e instanceof l&&this._map.addMarker(e)})})),this._loaded=!0)}resize(){this._map&&this._map.resize()}flyTo(e,t){this._map&&this._map.flyTo(e,t)}_removeMarker(e){var t;null==(t=this._map)||t.removeMarker(e)}_onMarkerChangedEvent(e){this._map&&this._map.onMarkerChanged(e.detail.marker,e.detail.property)}};OrMap.styles=p,__decorate([a({type:Object})],OrMap.prototype,"cluster",void 0),__decorate([a({type:String,converter:{fromAttribute(e,t){if(!e)return;let o=e.split(",");if(2===o.length)return new n(Number(o[0]),Number(o[1]))},toAttribute(e,t){let o=m.getLngLat(e);return o?""+o.lng+","+o.lat:""}}})],OrMap.prototype,"center",void 0),__decorate([a({type:Number})],OrMap.prototype,"zoom",void 0),__decorate([a({type:Boolean})],OrMap.prototype,"showGeoCodingControl",void 0),__decorate([a({type:Boolean})],OrMap.prototype,"showBoundaryBoxControl",void 0),__decorate([a({type:Boolean})],OrMap.prototype,"useZoomControl",void 0),__decorate([a({type:Object})],OrMap.prototype,"geoJson",void 0),__decorate([a({type:Boolean})],OrMap.prototype,"showGeoJson",void 0),__decorate([a({type:Array})],OrMap.prototype,"boundary",void 0),__decorate([s("#map")],OrMap.prototype,"_mapContainer",void 0),__decorate([s("slot")],OrMap.prototype,"_slotElement",void 0),OrMap=__decorate([r("or-map")],OrMap);export{m as Util,n as LngLat,OrMap};