var __decorate=this&&this.__decorate||function(e,t,i,a){var n,s=arguments.length,l=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,i):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,a);else for(var r=e.length-1;r>=0;r--)(n=e[r])&&(l=(s<3?n(l):s>3?n(t,i,l):n(t,i))||l);return s>3&&l&&Object.defineProperty(t,i,l),l};import{html as e}from"lit";import{customElement as t}from"lit/decorators.js";import{WidgetSettings as i}from"../util/widget-settings";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-vaadin-number-field value=${this.widgetConfig.min} max=${this.widgetConfig.max}
                                                    @change=${e=>this.onMinMaxValueChange("min",e)}>
                                <or-translate slot="label" value="min"></or-translate>
                            </or-vaadin-number-field>
                            <or-vaadin-number-field value=${this.widgetConfig.max} min=${this.widgetConfig.min}
                                                    @change=${e=>this.onMinMaxValueChange("max",e)}>
                                <or-translate slot="label" value="max"></or-translate>
                            </or-vaadin-number-field>
                        </div>
                        <div>
                            <or-vaadin-number-field value=${this.widgetConfig.decimals} min="0"
                                                    @change=${e=>this.onDecimalsChange(e)}>
                                <or-translate slot="label" value="decimals"></or-translate>
                            </or-vaadin-number-field>
                        </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){let i=t.currentTarget;if(!i.checkValidity())return;let a=Number(i.value);switch(e){case"max":this.widgetConfig.max=a,this.widgetConfig.thresholds.sort((e,t)=>t[0]-e[0]).forEach((e,t)=>{e[0]=Math.max(Math.min(e[0],a-t-1),this.widgetConfig.min)});break;case"min":{this.widgetConfig.min=a;let e=this.widgetConfig.thresholds.sort((e,t)=>e[0]<t[0]?-1:1);e[0][0]=a,e.forEach((e,t)=>{e[0]=Math.min(Math.max(e[0],a+t),this.widgetConfig.max)})}}this.notifyConfigUpdate()}onDecimalsChange(e){let t=e.currentTarget;t.checkValidity()&&(this.widgetConfig.decimals=Number(t.value),this.notifyConfigUpdate())}onThresholdChange(e){this.widgetConfig.thresholds=e.detail,this.notifyConfigUpdate()}};GaugeSettings=__decorate([t("gauge-settings")],GaugeSettings);export{GaugeSettings};