import{r as i,c as t,h as s,H as a,g as e}from"./p-a3dfaaf0.js";const h=class{constructor(s){i(this,s),this.spatialPickerInit=t(this,"spatialPickerInit",7),this.valueChanged=t(this,"valueChanged",7),this.label="Select spatial area",this.showMapIcon=!0,this.value="",this.precision=2,this.minZoom=0,this.maxZoom=24,this.zoom=2,this.latitude=0,this.longitude=0,this.fitWorld=!1,this.autocomplete=!1,this.disabled=!1,this.useAsIcon=!1,this.selectedArea="",this.displayMap=!1}componentDidLoad(){this.inputEl=this.el.querySelector("gd-input"),this.onValueChanged(this.value),this.useAsIcon&&document.addEventListener("click",i=>{i.target.closest(".spatial-icon-btn")||this.el.querySelector(".map-wrapper").classList.contains("hide")||this.el.querySelector(".map-wrapper").classList.add("hide")})}handleMapInit(i){this.map=i,this.map.addDrawControl(),this.spatialPickerInit.emit(this.map),this.value&&this.drawSpatialArea(this.value)}handleDraw(i){let t=i.getNorthEast(),s=i.getSouthWest(),a=this.map.normalizeBox([s.lng,s.lat,t.lng,t.lat]),e=this.formatValueToPrecision(a.join(","),this.precision);this.handleSpatialAreaChanged(e)}onValueChanged(i,t=!1){let s=t?this.formatValueToPrecision(i,this.precision):i;s.indexOf("NaN")>-1||(this.drawSpatialArea(s),this.handleSpatialAreaChanged(s))}setValueToInputValue(i){this.value=i}handleSpatialAreaChanged(i){this.selectedArea=i,this.valueChanged.emit(i)}formatValueToPrecision(i,t){return i&&i.split(",").map(i=>parseFloat(i).toFixed(t)).join(",")}drawSpatialArea(i){if(!this.map||!i)return;let t=i.split(",").map(i=>parseFloat(i));t.length<4||(t[0]>t[2]&&(t[2]+=360),this.map.drawRectangle([[t[3],t[2]],[t[1],t[0]]]))}showMapDisplay(){if(this.disabled)return;const i=this.el.querySelector(".map-wrapper");this.useAsIcon&&i.classList.contains("hide")?(this.el.querySelector(".map-wrapper").classList.remove("hide"),this.displayMap=!0):this.el.querySelector(".map-wrapper").classList.add("hide")}showMap(){setTimeout(()=>{this.map.refreshSize()},10)}renderMap(){return s("gd-map",{"min-zoom":this.minZoom,"max-zoom":this.maxZoom,zoom:this.zoom,latitude:this.latitude,longitude:this.longitude,"fit-world":this.fitWorld,width:this.mapWidth,height:this.mapHeight,onMapInit:i=>this.handleMapInit(i.detail),onDraw:i=>this.handleDraw(i.detail),onClearDraw:()=>this.onValueChanged(null),resize:this.displayMap})}render(){return s(a,{class:{"spatial-icon-btn":this.useAsIcon}},this.useAsIcon?s("div",{class:"spatial-btn-wrapper"},s("bs-button",{variant:"light",disabled:this.disabled,title:this.label,onClick:()=>this.showMapDisplay()},s("bs-icon",{icon:"fas fa-map",size:20})),s("div",{class:"map-wrapper hide"},s("div",{class:"map-container"},this.renderMap()))):s("div",null,s("bs-form-row",null,s("bs-form-group",null,s("bs-form-label",null,this.label),s("bs-form-control",{"control-id":"spatialpicker-"+this.label.replace(/ /g,""),as:"input",name:"spatialpicker-"+this.label.replace(/ /g,""),type:"text",value:this.selectedArea,onBsInput:i=>{var t,s;return this.setValueToInputValue(null===(s=null===(t=null==i?void 0:i.detail)||void 0===t?void 0:t.target)||void 0===s?void 0:s.value)},onClick:()=>this.showMap()}))),s("div",{class:"map-container"},this.renderMap())))}get el(){return e(this)}static get watchers(){return{value:["onValueChanged"]}}};h.style="gd-spatial-picker{box-sizing:content-box;display:inline-block;position:relative}.map-container{position:relative;min-width:10rem;padding:0.5rem 0;margin:0 15px;font-size:1rem;color:#212529;text-align:left;list-style:none;background-color:#fff;background-clip:padding-box;border:1px solid rgba(0, 0, 0, 0.15);border-radius:0.25rem}gd-spatial-picker.spatial-icon-btn{position:relative;display:flex}.spatial-icon-btn .spatial-btn-wrapper{position:relative}.spatial-icon-btn bs-button{border-radius:0px;height:100%;display:flex}.spatial-icon-btn .map-wrapper{position:absolute;right:0px;width:inherit;height:inherit;z-index:1;padding:0px;margin:0px}.spatial-icon-btn .map-wrapper.hide{display:none}";export{h as gd_spatial_picker}