var __decorate=this&&this.__decorate||function(e,t,r,i){var a,s=arguments.length,n=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,i);else for(var o=e.length-1;o>=0;o--)(a=e[o])&&(n=(s<3?a(n):s>3?a(t,r,n):a(t,r))||n);return s>3&&n&&Object.defineProperty(t,r,n),n},__awaiter=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))(function(a,s){function n(e){try{u(i.next(e))}catch(e){s(e)}}function o(e){try{u(i.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?a(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(n,o)}u((i=i.apply(e,t||[])).next())})};import{css as e,html as t,LitElement as r}from"lit";import{customElement as i,property as a,state as s}from"lit/decorators.js";import{AssetModelUtil as n}from"@openremote/model";import{AssetQueryOperator as o,getAssetIdsFromQuery as u,getAssetTypeFromQuery as l}from"../index";import{InputType as d}from"@openremote/or-mwc-components/or-mwc-input";import"@openremote/or-attribute-input";import{Util as p}from"@openremote/core";import{i18next as c,translate as T}from"@openremote/or-translate";import{buttonStyle as E}from"../style";import{OrRulesJsonRuleChangedEvent as h}from"./or-rule-json-viewer";import"./modals/or-rule-radial-modal";import{ifDefined as _}from"lit/directives/if-defined.js";import{when as m}from"lit/directives/when.js";import N from"moment";let style=e`
    
    ${E}
    
    :host {
        display: block;
    }
    
    .attribute-group {
        flex-grow: 1;
        display: flex;
        align-items: start;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .min-width {
        min-width: 200px;
    }
    
    .attribute-group > * {
        margin: 10px 3px 6px 3px;
    }
    .attributes {
        flex: 1 1 min-content;
        display: flex;
        flex-direction: column;
        row-gap: 10px;
    }
    or-icon.small {
        --or-icon-width: 14px;
        --or-icon-height: 14px;
    }
    .attribute {
        display: flex;
        align-items: center;
    }
    .attribute > div {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
    }
    .attribute > div > or-rule-radial-modal {
        min-width: auto;
    }
    .attribute > div > or-mwc-input[type="button"] {
        min-width: auto;
    }
    .attribute > div > or-mwc-input:not([type="button"]) {
        width: 200px;
    }
    .attribute > div > or-attribute-input {
        width: 200px;
    }
    .attribute > div > * {
        min-width: 200px;
    }
    .button-clear {
        margin-left: auto;
    }
    .attribute:hover .button-clear {
        visibility: visible;
    }
    
    .invalidLabel {
        display: flex;
        align-items: center;
        margin: 14px 3px auto 0;
        height: 48px; /* Same as the icon size */
    }
`,OrRuleAssetQuery=class extends T(c)(r){constructor(){super(),this._loading=!1,this._queryOperatorsMap={},this._queryOperatorsMap.GEO_JSONPoint=[o.EQUALS,o.NOT_EQUALS,o.WITHIN_RADIUS,o.OUTSIDE_RADIUS,o.WITHIN_RECTANGLE,o.OUTSIDE_RECTANGLE,o.INSIDE_AREA,o.OUTSIDE_AREA,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.string=[o.EQUALS,o.NOT_EQUALS,o.CONTAINS,o.NOT_CONTAINS,o.STARTS_WITH,o.NOT_STARTS_WITH,o.ENDS_WITH,o.NOT_ENDS_WITH,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.number=[o.EQUALS,o.NOT_EQUALS,o.GREATER_THAN,o.GREATER_EQUALS,o.LESS_THAN,o.LESS_EQUALS,o.BETWEEN,o.NOT_BETWEEN,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.boolean=[o.IS_TRUE,o.IS_FALSE,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.array=[o.CONTAINS,o.NOT_CONTAINS,o.INDEX_CONTAINS,o.NOT_INDEX_CONTAINS,o.LENGTH_EQUALS,o.NOT_LENGTH_EQUALS,o.LENGTH_LESS_THAN,o.LENGTH_GREATER_THAN,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.object=[o.CONTAINS_KEY,o.NOT_CONTAINS_KEY,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR]}refresh(){this._cache=void 0}attributePredicateEditorTemplate(e,r,i){let a=e.assetDescriptor,s=this.getOperator(i),o=this.getAttributeName(i),u=r&&r.attributes&&o?r.attributes[o]:void 0,l=[],T=n.getAttributeAndValueDescriptors(r?r.type:a.name,u||o,u);(l=r&&r.attributes?Object.values(r.attributes).filter(e=>e.meta&&(e.meta.hasOwnProperty("ruleState")?e.meta.ruleState:e.meta.hasOwnProperty("agentLink"))).map(e=>{let t=n.getAttributeAndValueDescriptors(r.type,e.name,e),i=p.getAttributeLabel(e,t[0],r.type,!1);return[e.name,i]}):e&&e.attributeDescriptors?e.attributeDescriptors.map(e=>{let t=n.getAttributeAndValueDescriptors(a.name,e),r=p.getAttributeLabel(void 0,t?t[0]:void 0,a.name,!1);return[e.name,r]}):[]).sort(p.sortByString(e=>e[1]));let E=o?this.getOperators(a,T?T[0]:void 0,T?T[1]:void 0,u,o):[];return t`
            <or-mwc-input type="${d.SELECT}" @or-mwc-input-changed="${e=>this.setAttributeName(i,e.detail.value)}" .readonly="${this.readonly||!1}" .options="${l}" .value="${o}" .label="${c.t("attribute")}"></or-mwc-input>
            ${o?t`<or-mwc-input type="${d.SELECT}" @or-mwc-input-changed="${e=>this.setOperator(a,u,o,i,e.detail.value)}" .readonly="${this.readonly||!1}" .options="${E}" .value="${s}" .label="${c.t("operator")}"></or-mwc-input>`:""}
            ${i?this.attributePredicateValueEditorTemplate(a,r,i):""}
        `}attributePredicateValueEditorTemplate(e,r,i){var a,s,u,p,T,E,m;if(this.getOperator(i)===o.NOT_UPDATED_FOR){let e=i.timestampOlderThan?N.duration(i.timestampOlderThan):void 0;return t`
                <or-mwc-input type="${d.NUMBER}" 
                              min="0"
                              .value="${null==e?void 0:e.asMinutes()}"
                              label="${c.t("rulesEditorDuration")}"
                              @or-mwc-input-changed="${e=>{let t=e.detail.value,r=N.duration(t,"minutes");i.timestampOlderThan=t>0?r.toISOString():void 0,this.dispatchEvent(new h)}}">
                </or-mwc-input>`}let A=i.value;if(!e||!A)return"";let y=this.getAttributeName(i),O=l(this.query),b=r&&r.attributes&&y?r.attributes[y]:void 0,S=n.getAttributeAndValueDescriptors(O,y,b),v=A?A.value:void 0;switch(A.predicateType){case"string":return t`<or-attribute-input @or-attribute-input-changed="${e=>this.setValuePredicateProperty(A,"value",e.detail.value)}" .customProvider="${null==(a=this.config)?void 0:a.inputProvider}" .label="${c.t("value")}" .assetType="${O}" .attributeDescriptor="${S[0]}" .attributeValueDescriptor="${S[1]}" .value="${v}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>`;case"boolean":return t``;case"datetime":case"rect":default:return t`<span>NOT IMPLEMENTED</span>`;case"number":let g;if("BETWEEN"===A.operator)return t`
                        <or-attribute-input .inputType="${d.NUMBER}" @or-attribute-input-changed="${e=>this.setValuePredicateProperty(A,"value",e.detail.value)}" .customProvider="${null==(s=this.config)?void 0:s.inputProvider}" .label="${c.t("between")}" .assetType="${O}" .attributeDescriptor="${S[0]}" .attributeValueDescriptor="${S[1]}" .value="${v}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>
                        <span style="display: inline-flex; align-items: center;">&</span>
                        <or-attribute-input .inputType="${d.NUMBER}" @or-attribute-input-changed="${e=>this.setValuePredicateProperty(A,"rangeValue",e.detail.value)}" .customProvider="${null==(u=this.config)?void 0:u.inputProvider}" .label="${c.t("and")}" .assetType="${O}" .attributeDescriptor="${S[0]}" .attributeValueDescriptor="${S[1]}" .value="${A.rangeValue}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>
                    `;return(null==(T=null==(p=S[0])?void 0:p.format)?void 0:T.asSlider)&&(g=d.NUMBER),t`<or-attribute-input .inputType="${_(g)}" @or-attribute-input-changed="${e=>this.setValuePredicateProperty(A,"value",e.detail.value)}" .customProvider="${null==(E=this.config)?void 0:E.inputProvider}" .label="" .assetType="${O}" .attributeDescriptor="${S[0]}" .attributeValueDescriptor="${S[1]}" .value="${v}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>`;case"radial":return t`<or-rule-radial-modal .query="${this.query}" .assetDescriptor="${e}" .attributePredicate="${i}"></or-rule-radial-modal>`;case"geojson":let f="geojson"===A.predicateType&&A.geoJSON?(()=>{try{return{source:JSON.parse(A.geoJSON),layers:[]}}catch(e){return}})():void 0;return t`
                    <or-conf-map-geojson .geoJson="${f}" @update="${e=>{let t=e.detail.value,r=t&&t.source?JSON.stringify(t.source):"";this.setValuePredicateProperty(A,"geoJSON",r)}}"></or-conf-map-geojson>
                    `;case"value-empty":return"";case"array":return t`<or-attribute-input @or-attribute-input-changed="${e=>this.setValuePredicateProperty(A,"value",e.detail.value)}" .customProvider="${null==(m=this.config)?void 0:m.inputProvider}" .label="" .assetType="${O}" .attributeDescriptor="${S[0]}" .attributeValueDescriptor="${S[1]}" .value="${v}" .readonly="${this.readonly||!1}" .fullWidth="${!0}></or-attribute-input>`}}attributeDurationTemplate(e,r,i,a){var s,n;let u=null==(n=null==(s=this.query.attributes)?void 0:s.items)?void 0:n[r];if((u?this.getOperator(u):void 0)===o.NOT_UPDATED_FOR)return t``;if(!e.has(r))return t`
                <or-mwc-input type="${d.BUTTON}" .readonly="${this.readonly||!1}" icon="clock-plus-outline"
                              title="${c.t("rulesEditorAddDuration")}" @or-mwc-input-changed="${()=>i(r)}"
                ></or-mwc-input>
            `;{let i=e.get(r),s=i?N.duration(i):void 0;return t`
                <or-mwc-input type="${d.NUMBER}" min="0" .readonly="${this.readonly||!1}"
                              .value="${null==s?void 0:s.asMinutes()}" label="${c.t("rulesEditorDuration")}"
                              @or-mwc-input-changed="${e=>{let t=N.duration(e.detail.value,"minutes");t.asMinutes()>0?a(r,t.toISOString()):a(r,void 0)}}"
                ></or-mwc-input>
            `}}static get styles(){return style}shouldUpdate(e){return e.has("condition")&&(this._cache=void 0),super.shouldUpdate(e)}get query(){return this.condition.assets}get duration(){var e;return(null==(e=this.condition)?void 0:e.duration)?new Map(Object.entries(this.condition.duration).map(([e,t])=>[Number(e),t])):new Map}set duration(e){e.size>0?this.condition.duration=Object.fromEntries(e):this.condition.duration=void 0}render(){let e,r=l(this.query);if(!r)return t`<span class="invalidLabel">${c.t("errorOccurred")}</span>`;let i=this.assetInfos?this.assetInfos.find(e=>e.assetDescriptor.name===r):void 0;if(!i)return t`<span class="invalidLabel">${c.t("errorOccurred")}</span>`;this._cache||this._loading||this.loadAssets(r),this.query.attributes||(this.query.attributes={}),this.query.attributes.items&&0!==this.query.attributes.items.length||(this.query.attributes.items=[{}]);let a=!this.readonly&&this.query.attributes&&this.query.attributes.items&&this.query.attributes.items.length>1,s=u(this.query),n=s&&s.length>0?s[0]:"*",o=new Map([["*",c.t("anyOfThisType")]]),p=this._cache?this._cache.assets:[],T=p.length>25;return T&&this._selected&&o.set(this._selected.id,this._selected.name),t`
            <div class="attribute-group">
            
                <!-- Show SELECT input with 'loading' until the assets are retrieved -->
                ${m(!this._cache||this._loading,()=>t`
                    <or-mwc-input id="idSelect" class="min-width" type="${d.SELECT}" .readonly="${!0}" .label="${c.t("loading")}"></or-mwc-input>
                `,()=>{T?e=e=>__awaiter(this,void 0,void 0,function*(){if(yield this.loadAssets(r,e,n),e)return p.filter(t=>{var r;return null==(r=t.name)?void 0:r.toLowerCase().includes(e.toLowerCase())}).map(e=>[e.id,e.name]);if(p.length<=100)return p.forEach(e=>o.set(e.id,e.name)),[...o];{let e=p.find(e=>e.id===n);return e&&!Array.from(o.keys()).includes(e.id)&&o.set(e.id,e.name),[...o]}}):p.forEach(e=>o.set(e.id,e.name));let s=!this.readonly&&(!this.config||!this.config.controls||!0!==this.config.controls.hideWhenAddAttribute),u=e=>{this.duration=this.duration.set(e,void 0),this.requestUpdate()},l=(e,t)=>{console.debug("Updating duration of rule condition to ",t),this.duration=this.duration.set(e,t),this.dispatchEvent(new h),this.requestUpdate()};return t`
                        <or-mwc-input id="idSelect" class="min-width filledSelect" type="${d.SELECT}" .readonly="${this.readonly||!1}" .label="${c.t("asset")}" 
                                      .options="${[...o]}" .value="${n}" .searchProvider="${e}"
                                      @or-mwc-input-changed="${e=>{this._assetId=e.detail.value}}"
                        ></or-mwc-input>
                        <div class="attributes">
                            ${this.query.attributes&&this.query.attributes.items?this.query.attributes.items.map((e,r)=>t`
                                    ${r>0?t`<or-icon class="small" icon="ampersand"></or-icon>`:""}
                                    <div class="attribute">
                                        <div>
                                            ${this.attributePredicateEditorTemplate(i,"*"!==n?this._cache.assets.find(e=>e.id===n):void 0,e)}
                                            ${this.attributeDurationTemplate(this.duration,r,u,l)}
                                        </div>
                                    ${a?t`
                                        <button class="button-clear" @click="${()=>this.removeAttributePredicate(this.query.attributes,e)}"><or-icon icon="close-circle"></or-icon></input>
                                    </div>`:""}
                                `):""}
                            ${s?t`
                                <or-mwc-input class="plus-button" type="${d.BUTTON}" icon="plus"
                                              label="rulesEditorAddAttribute" @or-mwc-input-changed="${e=>this.addAttributePredicate(this.query.attributes)}"></or-mwc-input>
                            `:""}
                        </div>
                    `})}
            </div>
        `}set _assetId(e){var t,r;e&&"*"!==e?(this._selected=null==(r=null==(t=this._cache)?void 0:t.assets)?void 0:r.find(t=>t.id===e),this.query.ids=[e]):this.query.ids=void 0,this.dispatchEvent(new h),this.requestUpdate()}getAttributeName(e){return e&&e.name?e.name.value:void 0}setAttributeName(e,t){e.name||(e.name={predicateType:"string"}),e.name.match="EXACT",e.name.value=t,e.value=void 0,this.dispatchEvent(new h),this.requestUpdate()}getOperatorMapValue(e,t,r,i,a){if(t&&r&&e[t+":"+r])return e[t+":"+r];if(a){if(e[a.name])return e[a.name];if(e[a.jsonType])return e[a.jsonType];if(a.arrayDimensions)return e.array}}getOperators(e,t,r,i,a){let s;return this.config&&this.config.controls&&this.config.controls.allowedAssetQueryOperators&&(s=this.getOperatorMapValue(this.config.controls.allowedAssetQueryOperators,l(this.query),a,t,r)),s||(s=this.getOperatorMapValue(this._queryOperatorsMap,l(this.query),a,t,r)),s?s.map(e=>[e,c.t(e)]):[]}getOperator(e){if(!e)return;if(void 0!==e.timestampOlderThan)return o.NOT_UPDATED_FOR;if(!e.value)return;let t=e.value;switch(t.predicateType){case"string":switch(t.match){case"EXACT":return t.negate?o.NOT_EQUALS:o.EQUALS;case"BEGIN":return t.negate?o.NOT_STARTS_WITH:o.STARTS_WITH;case"END":return t.negate?o.NOT_ENDS_WITH:o.ENDS_WITH;case"CONTAINS":return t.negate?o.NOT_CONTAINS:o.CONTAINS}return;case"boolean":return t.value?o.IS_TRUE:o.IS_FALSE;case"datetime":case"number":switch(t.operator){case"EQUALS":return t.negate?o.NOT_EQUALS:o.EQUALS;case"GREATER_THAN":return t.negate?o.LESS_EQUALS:o.GREATER_THAN;case"GREATER_EQUALS":return t.negate?o.LESS_THAN:o.GREATER_EQUALS;case"LESS_THAN":return t.negate?o.GREATER_EQUALS:o.LESS_THAN;case"LESS_EQUALS":return t.negate?o.GREATER_THAN:o.LESS_EQUALS;case"BETWEEN":return t.negate?o.NOT_BETWEEN:o.BETWEEN}return;case"radial":return t.negated?o.OUTSIDE_RADIUS:o.WITHIN_RADIUS;case"rect":return t.negated?o.OUTSIDE_RECTANGLE:o.WITHIN_RECTANGLE;case"geojson":return t.negated?o.OUTSIDE_AREA:o.INSIDE_AREA;case"array":if(t.value&&t.index)return t.negated?o.NOT_INDEX_CONTAINS:o.INDEX_CONTAINS;if(t.lengthEquals)return t.negated?o.NOT_LENGTH_EQUALS:o.LENGTH_EQUALS;if(t.lengthGreaterThan)return t.negated?o.LENGTH_LESS_THAN:o.LENGTH_GREATER_THAN;if(t.lengthLessThan)return t.negated?o.LENGTH_GREATER_THAN:o.LENGTH_LESS_THAN;return t.negated?o.NOT_CONTAINS:o.CONTAINS;case"value-empty":return t.negate?o.VALUE_NOT_EMPTY:o.VALUE_EMPTY}}updateDurationMap(e){if(this.duration){let t=Array.from(this.duration.entries()).filter(([t,r])=>t!==e).map(([t,r])=>[t>e?t-1:t,r]);this.duration=new Map(t)}}setOperator(e,t,r,i,a){let s;if(!this.query||!this.query.attributes||!this.query.attributes.items||0===this.query.attributes.items.length)return;if(!a){i.value=void 0,this.dispatchEvent(new h),this.requestUpdate();return}let u=n.getAttributeAndValueDescriptors(e.name,t||r);if(!u||!u[1]||!a){i.value=void 0,this.dispatchEvent(new h),this.requestUpdate();return}i.timestampOlderThan=void 0;let l=u[1];switch(a){case o.INDEX_CONTAINS:case o.NOT_INDEX_CONTAINS:case o.LENGTH_EQUALS:case o.NOT_LENGTH_EQUALS:case o.LENGTH_LESS_THAN:case o.LENGTH_GREATER_THAN:l.arrayDimensions&&(s={predicateType:"array",negated:a===o.NOT_INDEX_CONTAINS||a===o.NOT_LENGTH_EQUALS,index:a===o.INDEX_CONTAINS||a===o.NOT_INDEX_CONTAINS?0:void 0,lengthEquals:a===o.LENGTH_EQUALS||a===o.NOT_LENGTH_EQUALS?0:void 0,lengthGreaterThan:a===o.LENGTH_GREATER_THAN?0:void 0,lengthLessThan:a===o.LENGTH_GREATER_THAN?0:void 0});break;case o.WITHIN_RADIUS:case o.OUTSIDE_RADIUS:s={predicateType:"radial",negated:a===o.OUTSIDE_RADIUS,lat:0,lng:0,radius:50};break;case o.WITHIN_RECTANGLE:case o.OUTSIDE_RECTANGLE:s={predicateType:"rect",negated:a===o.OUTSIDE_RECTANGLE,latMin:-.1,lngMin:-.1,latMax:.1,lngMax:.1};break;case o.INSIDE_AREA:case o.OUTSIDE_AREA:s={predicateType:"geojson",negated:a===o.OUTSIDE_AREA,geoJSON:""};break;case o.IS_TRUE:case o.IS_FALSE:if("boolean"===l.jsonType){s={predicateType:"boolean",value:a===o.IS_TRUE};break}case o.STARTS_WITH:case o.NOT_STARTS_WITH:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_STARTS_WITH,match:"BEGIN"});break;case o.ENDS_WITH:case o.NOT_ENDS_WITH:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_ENDS_WITH,match:"END"});break;case o.NOT_BETWEEN:s="number"===l.jsonType||"bigint"===l.jsonType?{predicateType:"number",operator:"BETWEEN",negate:!0}:{predicateType:"datetime",operator:"BETWEEN",negate:!0};break;case o.GREATER_THAN:case o.GREATER_EQUALS:case o.LESS_THAN:case o.LESS_EQUALS:case o.BETWEEN:s="number"===l.jsonType?{predicateType:"number",operator:p.getEnumKeyAsString(o,a)}:{predicateType:"datetime",operator:p.getEnumKeyAsString(o,a)};break;case o.EQUALS:case o.NOT_EQUALS:"date"===l.jsonType?s={predicateType:"datetime",negate:a===o.NOT_EQUALS,operator:"EQUALS"}:"number"===l.jsonType?s={predicateType:"number",negate:a===o.NOT_EQUALS,operator:"EQUALS"}:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_EQUALS,match:"EXACT"});break;case o.VALUE_EMPTY:s={predicateType:"value-empty"};break;case o.VALUE_NOT_EMPTY:s={predicateType:"value-empty",negate:!0};break;case o.CONTAINS:case o.NOT_CONTAINS:l.arrayDimensions?s={predicateType:"array",negated:a===o.NOT_CONTAINS}:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_CONTAINS,match:"CONTAINS"});break;case o.NOT_UPDATED_FOR:i.timestampOlderThan="";let d=this.query.attributes.items.indexOf(i);this.updateDurationMap(d)}i.value=s,this.dispatchEvent(new h),this.requestUpdate()}get attributePredicate(){return this.query&&this.query.attributes&&this.query.attributes.items&&this.query.attributes.items.length>0?this.query.attributes.items[0]:void 0}setValuePredicateProperty(e,t,r){e&&(e[t]=r,this.dispatchEvent(new h),this.requestUpdate())}removeAttributePredicate(e,t){let r=e.items.indexOf(t);r>=0&&(e.items.splice(r,1),this.updateDurationMap(r)),this.dispatchEvent(new h),this.requestUpdate()}addAttributePredicate(e){null!=e.items||(e.items=[]),e.items.push({}),this.dispatchEvent(new h),this.requestUpdate()}toggleAttributeGroup(e){"OR"===e.operator?e.operator="AND":e.operator="OR",this.dispatchEvent(new h),this.requestUpdate()}loadAssets(e,t,r){return __awaiter(this,void 0,void 0,function*(){var i,a,s,n,o,u,l;let d=[],c={limit:100};t&&(null!=c.names||(c.names=[]),c.names.push({predicateType:"string",value:t}));let T=(null==(i=this._cache)?void 0:i.query)&&p.objectsEqual(this._cache.query,c,!0);if(!this._loading&&!T){this._loading=!0,d.push(this.assetProvider(e,Object.assign({},c))),r&&"*"!==r&&d.push(this.assetProvider(e,{ids:[r]}));let t=yield Promise.all(d);this._loading=!1;let i=t.filter(e=>!!e).flat(),l=null!=(s=null==(a=this._cache)?void 0:a.assets.map(e=>e.id))?s:[];return this._cache={query:c,assets:[...null!=(o=null==(n=this._cache)?void 0:n.assets)?o:[],...null!=(u=null==i?void 0:i.filter(e=>!l.includes(e.id)))?u:[]]},i}return null==(l=this._cache)?void 0:l.assets})}};__decorate([a({type:Object,attribute:!1})],OrRuleAssetQuery.prototype,"condition",void 0),__decorate([a({type:Object})],OrRuleAssetQuery.prototype,"config",void 0),__decorate([a({type:Object})],OrRuleAssetQuery.prototype,"assetInfos",void 0),__decorate([a({type:Object})],OrRuleAssetQuery.prototype,"assetProvider",void 0),__decorate([s()],OrRuleAssetQuery.prototype,"_cache",void 0),__decorate([s()],OrRuleAssetQuery.prototype,"_selected",void 0),OrRuleAssetQuery=__decorate([i("or-rule-asset-query")],OrRuleAssetQuery);export{OrRuleAssetQuery};