var __decorate=this&&this.__decorate||function(e,t,a,r){var o,i=arguments.length,l=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,a,r);else for(var d=e.length-1;d>=0;d--)(o=e[d])&&(l=(i<3?o(l):i>3?o(t,a,l):o(t,a))||l);return i>3&&l&&Object.defineProperty(t,a,l),l};import{html as e,LitElement as t}from"lit";import{customElement as a,property as r}from"lit/decorators.js";import{getAssetTypeFromQuery as o}from"../../index";import{InputType as i}from"@openremote/or-mwc-components/or-mwc-input";import{i18next as l,translate as d}from"@openremote/or-translate";import{OrRulesJsonRuleChangedEvent as n}from"../or-rule-json-viewer";import{OrMwcDialogOpenedEvent as c}from"@openremote/or-mwc-components/or-mwc-dialog";import{OrMapClickedEvent as s}from"@openremote/or-map";let OrRuleRadialModal=class extends d(l)(t){constructor(){super(),this.addEventListener(c.NAME,this.initRadialMap)}initRadialMap(){let e=this.shadowRoot.getElementById("radial-modal");if(!e)return;let t=e.shadowRoot.querySelector(".or-map");if(t){t.addEventListener(s.NAME,t=>{let a=t.detail.lngLat,r=e.shadowRoot.querySelector(".location-lat"),o=e.shadowRoot.querySelector(".location-lng");r.value=a.lat,o.value=a.lng;let i=new Event("change");r.dispatchEvent(i),o.dispatchEvent(i),this.setValuePredicateProperty("lat",a.lat),this.setValuePredicateProperty("lng",a.lng)});let a=e.shadowRoot.querySelector(".location-lat"),r=e.shadowRoot.querySelector(".location-lng");if(r.value&&a.value){let e=[parseFloat(r.value),parseFloat(a.value)];t.flyTo(e,15)}else t.flyTo()}}getAttributeName(e){return e&&e.name?e.name.value:void 0}setValuePredicateProperty(e,t){this.attributePredicate&&this.attributePredicate.value&&(this.attributePredicate.value[e]=t,this.attributePredicate=Object.assign({},this.attributePredicate),this.dispatchEvent(new n),this.requestUpdate())}renderDialogHTML(t){let a=this.shadowRoot.getElementById("radial-modal");a&&(a.content=e`
                <div style="display:grid">
                    <or-map class="or-map" type="VECTOR" style="border: 1px solid #d5d5d5; height: 400px; min-width: 300px; margin-bottom: 20px;">
                        <or-map-marker active color="#FF0000" icon="information" lat="${t.lat}" lng="${t.lng}" radius="${t.radius}"></or-map-marker>
                    </or-map>
                
                    <div class="layout horizontal">
                        <input hidden class="location-lng"  required placeholder=" " type="text" .value="${t&&t.lng?t.lng:null}" />
                        <input hidden class="location-lat" required placeholder=" " type="text" .value="${t&&t.lat?t.lat:null}" />
                    </div>

                    <label>${l.t("radiusMin")}</label>
                    <input @change="${e=>this.setValuePredicateProperty("radius",parseInt(e.target.value))}" style="max-width: calc(50% - 30px);" required placeholder=" " min="100" type="number" .value="${t&&t.radius?t.radius:100}" />
                </div>`)}render(){if(!this.attributePredicate||!this.query)return e``;let t=this.attributePredicate.value;if(!this.assetDescriptor||!t)return e``;this.getAttributeName(this.attributePredicate),o(this.query);let a=t||void 0,r=[{actionName:"cancel",content:e`<or-mwc-input class="button" .type="${i.BUTTON}" label="cancel"></or-mwc-input>`,action:()=>{}},{actionName:"ok",default:!0,content:e`<or-mwc-input class="button" .type="${i.BUTTON}" label="ok"></or-mwc-input>`,action:()=>{}}],l=()=>{let e=this.shadowRoot.getElementById("radial-modal");e&&(e.dismissAction=null,e.open(),this.renderDialogHTML(a))};return this.renderDialogHTML(a),e`
            <or-mwc-input .type="${i.BUTTON}" label="area" @or-mwc-input-changed="${l}"></or-mwc-input>
            <or-mwc-dialog id="radial-modal" heading="area" .actions="${r}"></or-mwc-dialog>
        `}};__decorate([r({type:Object})],OrRuleRadialModal.prototype,"assetDescriptor",void 0),__decorate([r({type:Object})],OrRuleRadialModal.prototype,"attributePredicate",void 0),__decorate([r({type:Object})],OrRuleRadialModal.prototype,"query",void 0),OrRuleRadialModal=__decorate([a("or-rule-radial-modal")],OrRuleRadialModal);export{OrRuleRadialModal};