var __decorate=this&&this.__decorate||function(e,t,i,s){var d,r=arguments.length,a=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,s);else for(var n=e.length-1;n>=0;n--)(d=e[n])&&(a=(r<3?d(a):r>3?d(t,i,a):d(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a},__awaiter=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))(function(d,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function n(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?d(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(a,n)}o((s=s.apply(e,t||[])).next())})};import{html as e,LitElement as t,unsafeCSS as i}from"lit";import{customElement as s,property as d,state as r}from"lit/decorators.js";import{style as a}from"./style";import{until as n}from"lit/directives/until.js";import{WidgetService as o}from"./service/widget-service";import{WidgetSettingsChangedEvent as l}from"./util/widget-settings";import{guard as g}from"lit/directives/guard.js";import{i18next as c,translate as h}from"@openremote/or-translate";let tableStyle=require("@material/data-table/dist/mdc.data-table.css"),OrDashboardWidgetsettings=class extends h(c)(t){static get styles(){return[i(tableStyle),a]}forceParentUpdate(e,t=!1){this.requestUpdate(),this.dispatchEvent(new CustomEvent("update",{detail:{changes:e,force:t}}))}render(){var t;return e`
            <div style="padding: 12px; border-bottom: 1px solid #E0E0E0">
                <or-vaadin-text-field value=${null==(t=this.selectedWidget)?void 0:t.displayName} required minlength="1" @change=${e=>{let t=e.currentTarget;t.checkValidity()&&this.setDisplayName(t.value)}}>
                    <or-translate slot="label" value="name"></or-translate>
                </or-vaadin-text-field>
            </div>
            <div>
                ${g([this.selectedWidget],()=>e`
                    ${n(this.generateContent(this.selectedWidget.widgetTypeId),e`Loading...`)}
                `)}
            </div>
        `}setDisplayName(e){this.selectedWidget.displayName=e,this.forceParentUpdate(new Map([["widget",this.selectedWidget]]))}generateContent(t){return __awaiter(this,void 0,void 0,function*(){if(!this.settingsElem||this.settingsElem.id!==this.selectedWidget.id){let e=o.getManifest(t);this.settingsElem=this.initSettings(e)}return e`
            ${this.settingsElem}
        `})}initSettings(e){let t=e.getSettingsHtml(this.selectedWidget.widgetConfig);return t.id=this.selectedWidget.id,t.getDisplayName=()=>this.selectedWidget.displayName,t.setDisplayName=e=>this.setDisplayName(e),t.getEditMode=()=>!0,t.getWidgetLocation=()=>{var e,t,i,s;return{x:null==(e=this.selectedWidget.gridItem)?void 0:e.x,y:null==(t=this.selectedWidget.gridItem)?void 0:t.y,w:null==(i=this.selectedWidget.gridItem)?void 0:i.w,h:null==(s=this.selectedWidget.gridItem)?void 0:s.h}},t.addEventListener(l.NAME,e=>this.onWidgetConfigChange(e)),t}onWidgetConfigChange(e){this.selectedWidget.widgetConfig=e.detail,this.forceParentUpdate(new Map([["widget",this.selectedWidget]]))}};__decorate([d({type:Object})],OrDashboardWidgetsettings.prototype,"selectedWidget",void 0),__decorate([r()],OrDashboardWidgetsettings.prototype,"settingsElem",void 0),OrDashboardWidgetsettings=__decorate([s("or-dashboard-widgetsettings")],OrDashboardWidgetsettings);export{OrDashboardWidgetsettings};