var __decorate=this&&this.__decorate||function(e,t,i,s){var d,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(d=e[a])&&(n=(r<3?d(n):r>3?d(t,i,n):d(t,i))||n);return r>3&&n&&Object.defineProperty(t,i,n),n},__awaiter=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))(function(d,r){function n(e){try{o(s.next(e))}catch(e){r(e)}}function a(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(n,a)}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{InputType as n}from"@openremote/or-mwc-components/or-mwc-input";import{style as a}from"./style";import{i18next as o}from"@openremote/or-translate";import{until as l}from"lit/directives/until.js";import{WidgetService as g}from"./service/widget-service";import{WidgetSettingsChangedEvent as c}from"./util/widget-settings";import{guard as h}from"lit/directives/guard.js";let tableStyle=require("@material/data-table/dist/mdc.data-table.css"),OrDashboardWidgetsettings=class extends 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;">
                <div>
                    <or-mwc-input .type="${n.TEXT}" style="width: 100%;" .value="${null==(t=this.selectedWidget)?void 0:t.displayName}" label="${o.t("name")}"
                                  @or-mwc-input-changed="${e=>this.setDisplayName(e.detail.value)}"
                    ></or-mwc-input>
                </div>
            </div>
            <div>
                ${h([this.selectedWidget],()=>e`
                    ${l(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=g.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(c.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};