var __decorate=this&&this.__decorate||function(t,e,o,r){var a,i=arguments.length,l=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(t,e,o,r);else for(var n=t.length-1;n>=0;n--)(a=t[n])&&(l=(i<3?a(l):i>3?a(e,o,l):a(e,o))||l);return i>3&&l&&Object.defineProperty(e,o,l),l};import{css as t,html as e,LitElement as o}from"lit";import{customElement as r,property as a}from"lit/decorators.js";import{InputType as i}from"@openremote/or-mwc-components/or-mwc-input";import{i18next as l,translate as n}from"@openremote/or-translate";import{OrMwcDialogOpenedEvent as s}from"@openremote/or-mwc-components/or-mwc-dialog";import{OrRulesJsonRuleChangedEvent as c}from"../or-rule-json-viewer";let checkValidity=(t,e)=>{if(t){let o=t.querySelectorAll("or-mwc-input");Array.prototype.slice.call(o).every(t=>{if(!t.shadowRoot)return!1;{let e=t.shadowRoot.querySelector("input, textarea");return t.type===i.SELECT||!!(e&&e.checkValidity())||(t._mdcComponent.valid=!1,t._mdcComponent.helperTextContent="required",!1)}})&&e.close()}},style=t`
    :host {
        display: flex;
        align-items: center;
    }
    :host > * {
        margin: 0 3px 6px;
    }
    .min-width {
        min-width: 200px;
    }
`,OrRuleAlarmModal=class extends n(l)(o){static get styles(){return style}constructor(){super(),this.title="settings",this.addEventListener(s.NAME,this.initDialog)}initDialog(){if(!this.shadowRoot.getElementById("alarm-modal"))return}renderDialogHTML(t){let o=this.shadowRoot.getElementById("alarm-modal");if(!this.shadowRoot)return;let r=this.shadowRoot.querySelector(".alarm-form-slot");if(o&&r){let t=document.createElement("div");r.assignedNodes({flatten:!0}).forEach(e=>{e instanceof HTMLElement&&t.appendChild(e)}),o.content=e`${t}`,o.dismissAction=null,this.requestUpdate()}}firstUpdated(t){t.has("action")&&this.renderDialogHTML(this.action)}checkForm(){let t=this.shadowRoot.host;if(this.shadowRoot){let e=this.shadowRoot.querySelector("or-rule-form-alarm");if(e&&e.shadowRoot)return checkValidity(e.shadowRoot.querySelector("form"),t)}}render(){var t;if(!this.action)return e``;let o=[{actionName:"cancel",content:e`<or-mwc-input class="button" .type="${i.BUTTON}" .label="${l.t("cancel")}"></or-mwc-input>`,action:t=>{}},{actionName:"",content:e`<or-mwc-input class="button" .type="${i.BUTTON}" .label="${l.t("ok")}" @or-mwc-input-changed="${this.checkForm}"></or-mwc-input>`}],r=()=>{let t=this.shadowRoot.getElementById("alarm-modal");t&&t.open()};return e`
            <or-mwc-input style="width: 200px" .type="${i.SELECT}" .value="${null==(t=this.action.alarm)?void 0:t.severity}" .label="${l.t("alarm.severity")}" .options="${[["LOW",l.t("alarm.severity_LOW")],["MEDIUM",l.t("alarm.severity_MEDIUM")],["HIGH",l.t("alarm.severity_HIGH")]]}" @or-mwc-input-changed="${t=>this.setActionAlarmSeverity(t.detail.value)}"></or-mwc-input>
            <or-mwc-input .type="${i.BUTTON}" .label="${l.t("settings")}" @or-mwc-input-changed="${r}"></or-mwc-input>
            <or-mwc-dialog id="alarm-modal" heading="${this.title}" .actions="${o}"></or-mwc-dialog>
            <slot class="alarm-form-slot"></slot>
        `}setActionAlarmSeverity(t){if(t&&this.action.alarm){let e=this.action.alarm;e.severity=t,this.action.alarm=Object.assign({},e)}this.dispatchEvent(new c),this.requestUpdate()}};__decorate([a({type:Object,attribute:!1})],OrRuleAlarmModal.prototype,"action",void 0),__decorate([a({type:String})],OrRuleAlarmModal.prototype,"title",void 0),__decorate([a({type:Object})],OrRuleAlarmModal.prototype,"query",void 0),OrRuleAlarmModal=__decorate([r("or-rule-alarm-modal")],OrRuleAlarmModal);export{OrRuleAlarmModal};