var __decorate=this&&this.__decorate||function(e,t,i,n){var a,s=arguments.length,o=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,n);else for(var l=e.length-1;l>=0;l--)(a=e[l])&&(o=(s<3?a(o):s>3?a(t,i,o):a(t,i))||o);return s>3&&o&&Object.defineProperty(t,i,o),o};import{html as e}from"lit";import{customElement as t}from"lit/decorators.js";import{WidgetSettings as i}from"../util/widget-settings";import{i18next as n}from"@openremote/or-translate";import{InputType as a}from"@openremote/or-mwc-components/or-mwc-input";let GaugeSettings=class extends i{render(){return e`
            <div>
                <!-- Attribute selection -->
                <settings-panel displayName="attributes" expanded="${!0}">
                    <attributes-panel .attributeRefs="${this.widgetConfig.attributeRefs}" .attributeFilter="${e=>["positiveInteger","positiveNumber","number","long","integer","bigInteger","negativeInteger","negativeNumber","bigNumber","integerByte","direction"].includes(e.type)}" style="padding-bottom: 12px;"
                                      @attribute-select="${e=>this.onAttributesSelect(e)}"
                    ></attributes-panel>
                </settings-panel>
                
                <!-- Min/max and decimals options-->
                <settings-panel displayName="values" expanded="${!0}">
                    <div style="padding-bottom: 12px; display: flex; flex-direction: column; gap: 12px;">
                        <div style="display: flex; gap: 8px;">
                            <or-mwc-input .type="${a.NUMBER}" label="${n.t("min")}" .max="${this.widgetConfig.max}" .value="${this.widgetConfig.min}"
                                          @or-mwc-input-changed="${e=>this.onMinMaxValueChange("min",e)}"
                            ></or-mwc-input>
                            <or-mwc-input .type="${a.NUMBER}" label="${n.t("max")}" .min="${this.widgetConfig.min}" .value="${this.widgetConfig.max}"
                                          @or-mwc-input-changed="${e=>this.onMinMaxValueChange("max",e)}"
                            ></or-mwc-input>
                        </div>
                        <div>
                            <or-mwc-input .type="${a.NUMBER}" style="width: 100%;" .value="${this.widgetConfig.decimals}" label="${n.t("decimals")}" .min="${0}"
                                          @or-mwc-input-changed="${e=>this.onDecimalsChange(e)}"
                            ></or-mwc-input>
                        </div>
                    </div>
                </settings-panel>
                
                <!-- Thresholds panel -->
                <settings-panel displayName="thresholds" expanded="${!0}">
                    <thresholds-panel .thresholds="${this.widgetConfig.thresholds}" .valueType="${"number"}" style="padding-bottom: 12px;"
                                      .min="${this.widgetConfig.min}" .max="${this.widgetConfig.max}"
                                      @threshold-change="${e=>this.onThresholdChange(e)}">
                    </thresholds-panel>
                </settings-panel>
            </div>
        `}onAttributesSelect(e){if(this.widgetConfig.attributeRefs=e.detail.attributeRefs,1===e.detail.attributeRefs.length){let t=e.detail.attributeRefs[0],i=e.detail.assets.find(e=>e.id===t.id);this.setDisplayName(i?`${i.name} - ${t.name}`:`${t.name}`)}this.notifyConfigUpdate()}onMinMaxValueChange(e,t){switch(e){case"max":this.widgetConfig.max=t.detail.value,this.widgetConfig.thresholds.sort((e,t)=>t[0]-e[0]).forEach((e,i)=>{e[0]=Math.max(Math.min(e[0],t.detail.value-i-1),this.widgetConfig.min)});break;case"min":{this.widgetConfig.min=t.detail.value;let e=this.widgetConfig.thresholds.sort((e,t)=>e[0]<t[0]?-1:1);e[0][0]=t.detail.value,e.forEach((e,i)=>{e[0]=Math.min(Math.max(e[0],t.detail.value+i),this.widgetConfig.max)})}}this.notifyConfigUpdate()}onDecimalsChange(e){this.widgetConfig.decimals=e.detail.value,this.notifyConfigUpdate()}onThresholdChange(e){this.widgetConfig.thresholds=e.detail,this.notifyConfigUpdate()}};GaugeSettings=__decorate([t("gauge-settings")],GaugeSettings);export{GaugeSettings};