var __decorate=this&&this.__decorate||function(t,e,s,r){var a,o=arguments.length,i=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,s,r);else for(var n=t.length-1;n>=0;n--)(a=t[n])&&(i=(o<3?a(i):o>3?a(e,s,i):a(e,s))||i);return o>3&&i&&Object.defineProperty(e,s,i),i};import{html as t,LitElement as e}from"lit";import{customElement as s,property as r}from"lit/decorators.js";import{classMap as a}from"lit-html/directives/class-map.js";import{AssetModelUtil as o}from"@openremote/model";import i,{subscribe as n,Util as d}from"@openremote/core";import"@openremote/or-icon";import{mapAssetCardStyle as p}from"./style";import{InputType as c}from"@openremote/or-mwc-components/or-mwc-input";import{getMarkerIconAndColorFromAssetType as l}from"./util";import{getMarkerConfigAttributeName as u}from"./markers/or-map-marker-asset";export class OrMapAssetCardLoadAssetEvent extends CustomEvent{constructor(t){super(OrMapAssetCardLoadAssetEvent.NAME,{bubbles:!0,composed:!0,detail:t})}}OrMapAssetCardLoadAssetEvent.NAME="or-map-asset-card-load-asset";export const DefaultConfig={default:{exclude:["notes"]},assetTypes:{}};let OrMapAssetCard=class extends n(i)(e){constructor(){super(...arguments),this.useAssetColor=!0}static get styles(){return p}shouldUpdate(t){return(!t.has("assetId")||(this.title="",this.assetIds=this.assetId&&this.assetId.length>0?[this.assetId]:void 0,1!==t.size))&&super.shouldUpdate(t)}_onEvent(t){if("asset"===t.eventType)switch(t.cause){case"READ":case"CREATE":case"UPDATE":this.asset=t.asset;break;case"DELETE":this.asset=void 0}"attribute"===t.eventType&&this.asset&&(this.asset=d.updateAsset(this.asset,t),this.requestUpdate())}_getCardConfig(){let t=this.config||DefaultConfig;return this.asset&&t.assetTypes&&t.assetTypes.hasOwnProperty(this.asset.type)?t.assetTypes[this.asset.type]:t.default}render(){if(!this.asset)return t``;let e=this._getIcon(),s=this._getColor(),r=this._getCardConfig(),i=Object.values(this.asset.attributes).filter(t=>"location"!==t.name),n=r&&r.include?r.include:void 0,p=r&&r.exclude?r.exclude:[],l=i.filter(t=>(!n||n.indexOf(t.name)>=0)&&(!p||0>p.indexOf(t.name))&&(!t.meta||!t.meta.hasOwnProperty("showOnDashboard")||!!d.getMetaValue("showOnDashboard",t))).sort(d.sortByString(t=>t.name)),h=u(this.markerconfig,this.asset.type);return t`
            <div id="card-container" style="${s?"--internal-or-map-asset-card-header-color: #"+s+";":""}">
                <div id="header">
                    ${e?t`<or-icon icon="${e}"></or-icon>`:""}
                    <span id="title">${this.asset.name}</span>
                </div>
                <div id="attribute-list">
                    <ul>
                        ${l.map(e=>{if(!this.asset||!this.asset.type)return;let s=o.getAttributeAndValueDescriptors(this.asset.type,e.name,e);if(s&&s.length){let r=d.getAttributeLabel(e,s[0],this.asset.type,!0),o=d.getAttributeValueAsString(e,s[0],this.asset.type,!1,"-"),i={highlighted:h===e.name};return t`<li class="${a(i)}"><span class="attribute-name">${r}</span><span class="attribute-value">${o}</span></li>`}})}
                    </ul>
                </div>
                ${r&&r.hideViewAsset?t``:t`
                    <div id="footer">
                        <or-mwc-input .type="${c.BUTTON}" label="viewAsset" @or-mwc-input-changed="${t=>{t.preventDefault(),this._loadAsset(this.asset.id)}}"></or-mwc-input>
                    </div>
                `}
            </div>
        `}_loadAsset(t){this.dispatchEvent(new OrMapAssetCardLoadAssetEvent(t))}_getIcon(){var t;if(this.asset)return(null==(t=l(o.getAssetDescriptor(this.asset.type)))?void 0:t.icon)||void 0}_getColor(){var t;if(this.asset){let e=null==(t=l(o.getAssetDescriptor(this.asset.type)))?void 0:t.color;if(e)return"string"==typeof e?e:e[0].colour}}};__decorate([r({type:String,reflect:!0,attribute:!0})],OrMapAssetCard.prototype,"assetId",void 0),__decorate([r({type:Object,attribute:!0})],OrMapAssetCard.prototype,"asset",void 0),__decorate([r({type:Object})],OrMapAssetCard.prototype,"config",void 0),__decorate([r({type:Object})],OrMapAssetCard.prototype,"markerconfig",void 0),__decorate([r({type:Boolean,attribute:!0})],OrMapAssetCard.prototype,"useAssetColor",void 0),OrMapAssetCard=__decorate([s("or-map-asset-card")],OrMapAssetCard);export{OrMapAssetCard};