var __decorate=this&&this.__decorate||function(t,e,o,r){var i,n=arguments.length,a=n<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,o,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(n<3?i(a):n>3?i(e,o,a):i(e,o))||a);return n>3&&a&&Object.defineProperty(e,o,a),a},__awaiter=this&&this.__awaiter||function(t,e,o,r){return new(o||(o=Promise))(function(i,n){function a(t){try{l(r.next(t))}catch(t){n(t)}}function s(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?i(t.value):((e=t.value)instanceof o?e:new o(function(t){t(e)})).then(a,s)}l((r=r.apply(t,e||[])).next())})};import{html as t,unsafeCSS as e}from"lit";import{property as o,query as r}from"lit/decorators.js";import"@openremote/or-asset-tree";import{i18next as i}from"@openremote/or-translate";import{DefaultColor2 as n,DefaultColor4 as a,DefaultColor5 as s,Util as l}from"@openremote/core";import{OrMwcDialog as d}from"@openremote/or-mwc-components/or-mwc-dialog";import{styleMap as c}from"lit/directives/style-map.js";import{ifDefined as u}from"lit/directives/if-defined.js";export class AttributePickerPickedEvent extends CustomEvent{}export class AttributePicker extends d{constructor(){super(...arguments),this.multiSelect=!1,this.showOnlyDatapointAttrs=!1,this.showOnlyRuleStateAttrs=!1,this.showPredictedDataAttrs=!1}connectedCallback(){super.connectedCallback(),this.heading=i.t("selectAttributes"),this._setDialogContent(),this._setDialogActions(),this.dismissAction=null,this.styles=this._getStyles()}setShowOnlyDatapointAttrs(t){return this.showOnlyDatapointAttrs=t,this}setShowOnlyRuleStateAttrs(t){return this.showOnlyRuleStateAttrs=t,this}setShowPredictedDataAttrs(t){return this.showPredictedDataAttrs=t,this}setMultiSelect(t){return this.multiSelect=t,this}setOpen(t){return super.setOpen(t),this}setHeading(t){return super.setHeading(t),this}setContent(t){throw Error("Cannot modify attribute picker content")}setActions(t){throw Error("Cannot modify attribute picker actions")}setDismissAction(t){throw Error("Cannot modify attribute picker dismiss action")}setStyles(t){throw Error("Cannot modify attribute picker styles")}setAvatar(t){throw Error("Cannot modify attribute picker avatar setting")}_updateDialogContent(){this._setDialogContent()}_updateDialogActions(){this._setDialogActions()}_getAttributesTemplate(e,o,r){return __awaiter(this,arguments,void 0,function*(e,o,r,i=!1,n){let a=Math.max((null==e?void 0:e.length)||0,(null==o?void 0:o.length)||0),s=[];for(let t=0;t<a;t++)s.push({text:l.getAttributeLabel(null==e?void 0:e[t],null==o?void 0:o[t],void 0,!0),value:(null==e?void 0:e[t].name)||(null==o?void 0:o[t].name)});let d=null==r?void 0:r.map(t=>s.findIndex(e=>e.value===t));return t`
            <or-vaadin-list-box id="attribute-selector" ?multiple=${i} .selectedValues=${u(d)}
                                @selected-changed=${t=>null==n?void 0:n([s[t.detail.value].value])}
                                @selected-values-changed=${t=>{var e,o;return null==n?void 0:n(null!=(o=null==(e=t.detail.value)?void 0:e.map(t=>s[t].value))?o:[])}}>
                ${s.map(e=>{var o,r,i;return t`
                    <or-vaadin-item style=${c(null!=(o=e.styleMap)?o:{})}>
                        ${null!=(i=null!=(r=e.text)?r:e.value)?i:t`<or-translate value="unknown"></or-translate>`}
                    </or-vaadin-item>
                `})}
            </or-vaadin-list-box>
        `})}_getStyles(){return`
            .attributes-header {
                line-height: 48px;
                padding: 0 15px;
                background-color: ${e(n)};
                font-weight: bold;
                border-bottom: 1px solid ${e(n)};
            }
            footer.mdc-dialog__actions {
                border-top: 1px solid ${e(s)};
            }
            #header {
                background-color: ${e(a)} !important;
            }
            #dialog-content {
                padding: 0;
            }
        `}}__decorate([o({type:Boolean})],AttributePicker.prototype,"multiSelect",void 0),__decorate([o({type:Boolean})],AttributePicker.prototype,"showOnlyDatapointAttrs",void 0),__decorate([o({type:Boolean})],AttributePicker.prototype,"showOnlyRuleStateAttrs",void 0),__decorate([o({type:Boolean})],AttributePicker.prototype,"showPredictedDataAttrs",void 0),__decorate([r("#add-btn")],AttributePicker.prototype,"addBtn",void 0);