var __decorate=this&&this.__decorate||function(t,e,s,r){var o,i=arguments.length,n=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,s,r);else for(var d=t.length-1;d>=0;d--)(o=t[d])&&(n=(i<3?o(n):i>3?o(e,s,n):o(e,s))||n);return i>3&&n&&Object.defineProperty(e,s,n),n},__awaiter=this&&this.__awaiter||function(t,e,s,r){return new(s||(s=Promise))(function(o,i){function n(t){try{a(r.next(t))}catch(t){i(t)}}function d(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(n,d)}a((r=r.apply(t,e||[])).next())})};import{OrWidget as t}from"./or-widget";import{state as e}from"lit/decorators.js";import s from"@openremote/core";import{showSnackbar as r}from"@openremote/or-mwc-components/or-mwc-snackbar";import{isAxiosError as o}from"@openremote/rest";import{WidgetSettings as i}from"./widget-settings";export class OrAssetWidget extends t{constructor(){super(...arguments),this.loadedAssets=[],this.assetAttributes=[]}static get styles(){return[...super.styles]}fetchAssets(){return __awaiter(this,arguments,void 0,function*(t=[]){return fetchAssetsByAttributeRef(t)})}queryAssets(t){return __awaiter(this,void 0,void 0,function*(){return fetchAssets(t)})}isAssetLoaded(t){return isAssetIdLoaded(this.loadedAssets,t)}isAttributeRefLoaded(t){return isAssetIdLoaded(this.loadedAssets,t.id)}}__decorate([e()],OrAssetWidget.prototype,"loadedAssets",void 0),__decorate([e()],OrAssetWidget.prototype,"assetAttributes",void 0),__decorate([e()],OrAssetWidget.prototype,"_error",void 0);export class AssetWidgetSettings extends i{constructor(){super(...arguments),this.loadedAssets=[]}fetchAssets(){return __awaiter(this,arguments,void 0,function*(t=[]){return fetchAssetsByAttributeRef(t)})}queryAssets(t){return __awaiter(this,void 0,void 0,function*(){return fetchAssets(t)})}isAssetLoaded(t){return isAssetIdLoaded(this.loadedAssets,t)}isAttributeRefLoaded(t){return isAssetIdLoaded(this.loadedAssets,t.id)}}function fetchAssetsByAttributeRef(){return __awaiter(this,arguments,void 0,function*(t=[]){return fetchAssets({ids:null==t?void 0:t.map(t=>t.id),select:{attributes:null==t?void 0:t.map(t=>t.name)}})})}function fetchAssets(t){return __awaiter(this,void 0,void 0,function*(){let e=[];return t.realm={name:s.displayRealm},yield s.rest.api.AssetResource.queryAssets(t).then(t=>{e=t.data}).catch(t=>{if(console.error(t),r(void 0,"errorOccurred"),o(t)){if("Network Error"===t.message)throw Error("youAreOffline");else if("ECONNABORTED"===t.code)throw Error("noAttributeDataTimeout")}}),e})}function isAssetIdLoaded(t,e){return(null==t?void 0:t.find(t=>t.id===e))!==void 0}__decorate([e()],AssetWidgetSettings.prototype,"loadedAssets",void 0);