/****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$4=new WeakMap;let n$3 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$4.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$4.set(s,t));}return t}toString(){return this.cssText}};const r$4=t=>new n$3("string"==typeof t?t:t+"",void 0,s$2),i$4=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(true===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$3(o,t,s$2)},S$1=(s,o)=>{if(e$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$4(e)})(t):t; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const{is:i$3,defineProperty:e$5,getOwnPropertyDescriptor:h$1,getOwnPropertyNames:r$3,getOwnPropertySymbols:o$3,getPrototypeOf:n$2}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$3(t,s),b={attribute:true,type:String,converter:u$1,reflect:false,useDefault:false,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let y$1 = class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$5(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h$1(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$2(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...r$3(t),...o$3(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$ET(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const h=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==h?this.removeAttribute(e):this.setAttribute(e,h),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=h.fromAttribute(s,t.type)??this._$Ej?.get(e)??null,this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){const e=this.constructor,h=this[t];if(i??=e.getPropertyOptions(t),!((i.hasChanged??f$1)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(e._$Eu(t,i))))return;this.C(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$EP());}C(t,s,{useDefault:i,reflect:e,wrapped:h},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??s??this[t]),true!==h||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(s=void 0),this._$AL.set(t,s)),true===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t));}async _$EP(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t){const{wrapped:t}=i,e=this[s];true!==t||this._$AL.has(s)||void 0===e||this.C(s,void 0,i,e);}}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EM();}catch(s){throw t=false,this._$EM(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}_$EM(){this._$AL=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return true}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM();}updated(t){}firstUpdated(t){}};y$1.elementStyles=[],y$1.shadowRootOptions={mode:"open"},y$1[d$1("elementProperties")]=new Map,y$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:y$1}),(a$1.reactiveElementVersions??=[]).push("2.1.0"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const t$2=globalThis,i$2=t$2.trustedTypes,s$1=i$2?i$2.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$2="?"+h,n$1=`<${o$2}>`,r$2=document,l=()=>r$2.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),T=Symbol.for("lit-noChange"),E=Symbol.for("lit-nothing"),A=new WeakMap,C=r$2.createTreeWalker(r$2,129);function P(t,i){if(!a(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const V=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"":3===i?"":"",c=f;for(let i=0;i"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$1:d>=0?(o.push(a),s.slice(0,d)+e$4+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [P(t,l+(t[s]||"")+(2===i?"":3===i?"":"")),o]};class N{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=V(t,s);if(this.el=N.createElement(f,n),C.currentNode=this.el.content,2===s||3===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=C.nextNode())&&d.length0){r.textContent=i$2?i$2.emptyScript:"";for(let i=0;i2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=E;}_$AI(t,i=this,s,e){const h=this.strings;let o=false;if(void 0===h)t=S(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==T,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new R(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const s=globalThis;let i$1 = class i extends y$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const r=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=B(r,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return T}};i$1._$litElement$=true,i$1["finalized"]=true,s.litElementHydrateSupport?.({LitElement:i$1});const o$1=s.litElementPolyfillSupport;o$1?.({LitElement:i$1});(s.litElementVersions??=[]).push("4.2.0"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const t$1=t=>(e,o)=>{ void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const o={attribute:true,type:String,converter:u$1,reflect:false,hasChanged:f$1},r$1=(t=o,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),"setter"===n&&((t=Object.create(t)).wrapped=true),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.C(o,void 0,t,e),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n(t){return (e,o)=>"object"==typeof o?r$1(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function r(r){return n({...r,state:true,attribute:false})} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const e$3=(e,t,c)=>(c.configurable=true,c.enumerable=true,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function e$2(e,r){return (n,s,i)=>{const o=t=>t.renderRoot?.querySelector(e)??null;return e$3(n,s,{get(){return o(this)}})}} function registerCustomCard(params){const windowWithCards=window;windowWithCards.customCards=windowWithCards.customCards||[];windowWithCards.customCards.push(Object.assign(Object.assign({},params),{preview:false}));} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const t={ATTRIBUTE:1},e$1=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}} /** * @license * Copyright 2018 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const e=e$1(class extends i{constructor(t$1){if(super(t$1),t$1.type!==t.ATTRIBUTE||"class"!==t$1.name||t$1.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return T}}); class DragScrollController{get enabled(){return this._enabled;}set enabled(value){if(value===this._enabled){return;}this._enabled=value;if(this._enabled){this._attach();}else {this._detach();}this._host.requestUpdate();}constructor(host,{selector,enabled}){this.mouseIsDown=false;this.scrolled=false;this.scrolling=false;this.scrollStartX=0;this.scrollLeft=0;this._enabled=true;this._mouseDown=event=>{const scrollContainer=this._scrollContainer;if(!scrollContainer){return;}this.scrollStartX=event.pageX-scrollContainer.offsetLeft;this.scrollLeft=scrollContainer.scrollLeft;this.mouseIsDown=true;this.scrolled=false;window.addEventListener("mousemove",this._mouseMove);window.addEventListener("mouseup",this._mouseUp,{once:true});};this._mouseUp=()=>{this.mouseIsDown=false;this.scrolling=false;this._host.requestUpdate();window.removeEventListener("mousemove",this._mouseMove);};this._mouseMove=event=>{if(!this.mouseIsDown){return;}const scrollContainer=this._scrollContainer;if(!scrollContainer){return;}const x=event.pageX-scrollContainer.offsetLeft;const scroll=x-this.scrollStartX;if(!this.scrolled){this.scrolled=Math.abs(scroll)>1;this.scrolling=this.scrolled;this._host.requestUpdate();}scrollContainer.scrollLeft=this.scrollLeft-scroll;};this._selector=selector;this._host=host;this.enabled=enabled!==null&&enabled!==void 0?enabled:true;host.addController(this);}hostUpdated(){if(!this.enabled||this._scrollContainer){return;}this._attach();}hostDisconnected(){this._detach();}_attach(){var _a;this._scrollContainer=(_a=this._host.renderRoot)===null||_a===void 0?void 0:_a.querySelector(this._selector);if(this._scrollContainer){this._scrollContainer.addEventListener("mousedown",this._mouseDown);}}_detach(){window.removeEventListener("mousemove",this._mouseMove);window.removeEventListener("mouseup",this._mouseUp);if(this._scrollContainer){this._scrollContainer.removeEventListener("mousedown",this._mouseDown);this._scrollContainer=undefined;}this.scrolled=false;this.scrolling=false;this.mouseIsDown=false;this.scrollStartX=0;this.scrollLeft=0;}} registerCustomCard({type:'badge-horizontal-container-card',name:'Badge Horizontal Container Card',description:'A card that displays badges in a horizontal layout.'});let BadgeHorizontalContainerCard=class BadgeHorizontalContainerCard extends i$1{constructor(){super(...arguments);this.preview=false;this._dragScrollController=new DragScrollController(this,{selector:".scroll",enabled:false});}static async getStubConfig(){return {type:"custom:badge-horizontal-container-card",badges:[]};}static async getConfigElement(){await Promise.resolve().then(function () { return badgeContainerEditor; });return document.createElement('badge-horizontal-container-card-editor');}setConfig(config){if(!config||!config.badges||!Array.isArray(config.badges)){throw new Error("Invalid configuration");}this._config=config;this._badges=config.badges.map(badge=>{const element=this._createCardElement(badge);return element;});}update(changedProperties){var _a;super.update(changedProperties);if(changedProperties.has("config")||changedProperties.has("preview")){this._dragScrollController.enabled=!this.preview&&((_a=this._config)===null||_a===void 0?void 0:_a.badges_wrap)==="scroll";}if(this._badges){if(changedProperties.has("hass")){this._badges.forEach(badge=>{badge.hass=this.hass;});}if(changedProperties.has("preview")){this._badges.forEach(card=>{card.preview=this.preview;});}}}_createCardElement(cardConfig){const element=document.createElement("hui-badge");element.hass=this.hass;element.preview=this.preview;element.config=cardConfig;element.load();return element;}render(){var _a;if(!this._config||!this._badges){return E;}if(this._badges.length===0){return x` No badges configured. Please add badges in the configuration. `;}const scrolling=this._dragScrollController.scrolling;return x`
${this._badges}
`;}getGridOptions(){return {columns:'full',rows:'auto'};}getLayoutOptions(){return {grid_columns:'full',grid_rows:'auto'};}getCardSize(){return 1;}static get styles(){return i$4` .badges { display: flex; align-items: flex-start; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0; } .badges > * { min-width: fit-content; } .badges.scroll { overflow: auto; max-width: 100%; scrollbar-color: var(--scrollbar-thumb-color) transparent; scrollbar-width: none; mask-image: linear-gradient(90deg, transparent 0%, black 8px, black calc(100% - 8px), transparent 100%); flex-wrap: nowrap; padding: 2px 0; } .badges.scroll:not(.nostart)::before, .badges.scroll::after { content: ""; position: relative; display: block; min-width: 0; height: 16px; background-color: transparent; } .left-align { justify-content: flex-start; } .right-align { justify-content: flex-end; } .no-wrap { flex-wrap: nowrap; } .scrolling { pointer-events: none; } `;}};__decorate([n({attribute:false})],BadgeHorizontalContainerCard.prototype,"hass",void 0);__decorate([n({type:Boolean})],BadgeHorizontalContainerCard.prototype,"preview",void 0);__decorate([n({attribute:false})],BadgeHorizontalContainerCard.prototype,"lovelace",void 0);__decorate([r()],BadgeHorizontalContainerCard.prototype,"_config",void 0);__decorate([r()],BadgeHorizontalContainerCard.prototype,"_badges",void 0);BadgeHorizontalContainerCard=__decorate([t$1('badge-horizontal-container-card')],BadgeHorizontalContainerCard); // Material Design Icons v7.4.47 var mdiArrowLeft = "M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"; var mdiCodeBraces = "M8,3A2,2 0 0,0 6,5V9A2,2 0 0,1 4,11H3V13H4A2,2 0 0,1 6,15V19A2,2 0 0,0 8,21H10V19H8V14A2,2 0 0,0 6,12A2,2 0 0,0 8,10V5H10V3M16,3A2,2 0 0,1 18,5V9A2,2 0 0,0 20,11H21V13H20A2,2 0 0,0 18,15V19A2,2 0 0,1 16,21H14V19H16V14A2,2 0 0,1 18,12A2,2 0 0,1 16,10V5H14V3H16Z"; var mdiDelete = "M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z"; var mdiDrag = "M7,19V17H9V19H7M11,19V17H13V19H11M15,19V17H17V19H15M7,15V13H9V15H7M11,15V13H13V15H11M15,15V13H17V15H15M7,11V9H9V11H7M11,11V9H13V11H11M15,11V9H17V11H15M7,7V5H9V7H7M11,7V5H13V7H11M15,7V5H17V7H15Z"; var mdiEye = "M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z"; var mdiListBoxOutline = "M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z"; var mdiPencil = "M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z"; const fireEvent=(node,type,detail,options)=>{options=options||{};detail=detail===null||detail===undefined?{}:detail;const event=new Event(type,{bubbles:options.bubbles===undefined?true:options.bubbles,cancelable:Boolean(options.cancelable),composed:options.composed===undefined?true:options.composed});event.detail=detail;node.dispatchEvent(event);return event;}; var safeIsNaN = Number.isNaN || function ponyfill(value) { return typeof value === 'number' && value !== value; }; function isEqual(first, second) { if (first === second) { return true; } if (safeIsNaN(first) && safeIsNaN(second)) { return true; } return false; } function areInputsEqual(newInputs, lastInputs) { if (newInputs.length !== lastInputs.length) { return false; } for (var i = 0; i < newInputs.length; i++) { if (!isEqual(newInputs[i], lastInputs[i])) { return false; } } return true; } function memoizeOne(resultFn, isEqual) { if (isEqual === void 0) { isEqual = areInputsEqual; } var cache = null; function memoized() { var newArgs = []; for (var _i = 0; _i < arguments.length; _i++) { newArgs[_i] = arguments[_i]; } if (cache && cache.lastThis === this && isEqual(newArgs, cache.lastArgs)) { return cache.lastResult; } var lastResult = resultFn.apply(this, newArgs); cache = { lastResult: lastResult, lastArgs: newArgs, lastThis: this, }; return lastResult; } memoized.clear = function clear() { cache = null; }; return memoized; } const SCHEMA=[{name:"badges_align",label:"Badges Alignment",selector:{select:{options:[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}]}}},{name:"badges_wrap",label:"Badges wrapping",selector:{select:{options:[{value:"wrap",label:"Wrap",image:{src:"/static/images/form/view_header_badges_wrap_wrap.svg",src_dark:"/static/images/form/view_header_badges_wrap_wrap_dark.svg"}},{value:"scroll",label:"Scroll",image:{src:"/static/images/form/view_header_badges_wrap_scroll.svg",src_dark:"/static/images/form/view_header_badges_wrap_scroll_dark.svg"}}],mode:"box"}}}];let BadgeContainerEditor=class BadgeContainerEditor extends i$1{constructor(){super(...arguments);this.index=0;this._selectedBadgeIndex=-1;this._GUImode=true;this._guiModeAvailable=true;this._schema=memoizeOne(()=>{var _a;return [{name:"new_badge",selector:{select:{options:[{value:"custom:hui-entity-badge",label:"Entity"},...((_a=window.customBadges)===null||_a===void 0?void 0:_a.map(badge=>({value:`custom:${badge.type}`,label:badge.name||badge.type})))],mode:"dropdown"}}}];});}setConfig(config){this._config=config;}render(){var _a,_b;if(!this.hass||!this._config){return E;}const selected=(_a=this._selectedBadgeIndex)!==null&&_a!==void 0?_a:-1;const isGuiMode=!this._cardEditorEl||this._GUImode;const backElement=x`
{this._selectedBadgeIndex=-1;this._GUImode=true;}} > ${this._selectedBadgeIndex!=-1?this._getBadgeName(this._config.badges[this._selectedBadgeIndex].type):""}
`;if(selected>-1){let badgeConfig=this._config.badges[selected];if(badgeConfig.type==="entity"){badgeConfig=Object.assign(Object.assign({},badgeConfig),{type:"custom:hui-entity-badge"});}return x` ${backElement} ${isGuiMode?x`
${this.hass.localize(`ui.panel.lovelace.editor.edit_card.tab_visibility`)}

${this.hass.localize(`ui.panel.lovelace.editor.edit_badge.visibility.explanation`)}

`:E} `;}return x` schema.label} @value-changed=${this._valueChanged} > Badges
${this._config.badges.map((badge,index)=>x`
${this._getBadgeName(badge.type)} ${this._getEntityName(badge)}
`)}
this.hass.localize("ui.panel.lovelace.editor.section.add_badge")} @value-changed=${this._handleBadgePicked} > `;}_getBadgeName(badgeType){var _a;if(badgeType=="custom:hui-entity-badge"||badgeType=="entity"){return "Entity Badge";}const badge=(_a=window.customBadges)===null||_a===void 0?void 0:_a.find(b=>b.type===badgeType.replace("custom:",""));return badge?badge.name||badgeType:badgeType;}_getEntityName(badgeConfig){if(!badgeConfig.entity){return "";}const entity=this.hass.states[badgeConfig.entity];if(!entity){return badgeConfig.entity;}return entity.attributes.friendly_name||entity.entity_id;}async _handleBadgePicked(ev){ev.stopPropagation();if(!this._config){return;}const badgeType=ev.detail.value.new_badge;if(!badgeType){return;}const badgeConfig=await this._getBadgeStubConfig(badgeType);badgeConfig.type=badgeType;const badges=[...this._config.badges,badgeConfig];this._config=Object.assign(Object.assign({},this._config),{badges});fireEvent(this,"config-changed",{config:this._config});}_toggleMode(){this._cardEditorEl.toggleMode();}async _getBadgeStubConfig(badgeType){const badgeClass=customElements.get(badgeType.replace("custom:",""));return await badgeClass.getStubConfig(this.hass,this.hass.entities,this.hass.entities);}_handleBadgeVisibilityChanged(ev){var _a,_b;ev.stopPropagation();if(!this._config){return;}const badges=[...this._config.badges];const conditions=ev.detail.value;const newBadge=Object.assign(Object.assign({},badges[this._selectedBadgeIndex]),{visibility:conditions});if(((_a=newBadge.visibility)===null||_a===void 0?void 0:_a.length)===0){delete newBadge.visibility;}badges[this._selectedBadgeIndex]=newBadge;this._config=Object.assign(Object.assign({},this._config),{badges});fireEvent(this,"config-changed",{config:this._config});(_b=this._cardEditorEl)===null||_b===void 0?void 0:_b.requestUpdate();}_handleConfigChanged(ev){ev.stopPropagation();if(!this._config){return;}const badges=[...this._config.badges];const newBadge=ev.detail.config;badges[this._selectedBadgeIndex]=newBadge;this._config=Object.assign(Object.assign({},this._config),{badges});this._guiModeAvailable=ev.detail.guiModeAvailable;fireEvent(this,"config-changed",{config:this._config});}_handleGUIModeChanged(ev){ev.stopPropagation();this._GUImode=ev.detail.guiMode;this._guiModeAvailable=ev.detail.guiModeAvailable;}_handleBadgeMoved(ev){var _a,_b;ev.stopPropagation();if(!((_a=this._config)===null||_a===void 0?void 0:_a.badges)||!this.hass){return;}const{oldIndex,newIndex}=ev.detail;const newBadges=(_b=this._config)===null||_b===void 0?void 0:_b.badges.concat();newBadges.splice(newIndex,0,newBadges.splice(oldIndex,1)[0]);this._config=Object.assign(Object.assign({},this._config),{badges:newBadges});fireEvent(this,'config-changed',{config:this._config});}editBadge(ev){var _a;const index=(_a=ev.currentTarget.index)!==null&&_a!==void 0?_a:-1;this._selectedBadgeIndex=index;this._GUImode=true;this._guiModeAvailable=true;}_deleteBadge(ev){var _a;ev.stopPropagation();const index=(_a=ev.currentTarget.index)!==null&&_a!==void 0?_a:-1;if(!this._config||index<0){return;}const badges=[...this._config.badges];badges.splice(index,1);this._config=Object.assign(Object.assign({},this._config),{badges});fireEvent(this,"config-changed",{config:this._config});}_valueChanged(ev){ev.stopPropagation();this._config=Object.assign(Object.assign({},this._config),ev.detail.value);fireEvent(this,"config-changed",{config:this._config});}static get styles(){return i$4` :host { display: flex; flex-direction: column; } .header { display: flex; justify-content: space-between; align-items: center; } .back-title { display: flex; align-items: center; font-size: 18px; } .handle { cursor: grab; padding-inline-end: 8px; align-self: flex-start; margin: 16px 0; display: flex; align-items: center; } .handle div { display: flex; flex-direction: column; justify-content: center; } .intro { margin: 0; color: var(--secondary-text-color); margin-bottom: 8px; } .secondary { color: var(--secondary-text-color); font-size: 12px; } .badge-item { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; } .edit-badge, .delete-badge { align-self: flex-start; margin: 4px 0px; } .label { margin-top: 24px; } ha-form:nth-of-type(2) { margin-top: 16px; } ha-svg-icon { color: var(--secondary-text-color); } ha-expansion-panel { padding: 12px 0; border-bottom: 2px solid var(--divider-color); } hui-card-element-editor { margin-top: 16px; } `;}};__decorate([n({attribute:false})],BadgeContainerEditor.prototype,"hass",void 0);__decorate([n({attribute:false})],BadgeContainerEditor.prototype,"lovelace",void 0);__decorate([n({type:Number})],BadgeContainerEditor.prototype,"index",void 0);__decorate([r()],BadgeContainerEditor.prototype,"_config",void 0);__decorate([r()],BadgeContainerEditor.prototype,"_selectedBadgeIndex",void 0);__decorate([r()],BadgeContainerEditor.prototype,"_GUImode",void 0);__decorate([r()],BadgeContainerEditor.prototype,"_guiModeAvailable",void 0);__decorate([e$2("hui-card-element-editor")],BadgeContainerEditor.prototype,"_cardEditorEl",void 0);BadgeContainerEditor=__decorate([t$1("badge-horizontal-container-card-editor")],BadgeContainerEditor); var badgeContainerEditor = /*#__PURE__*/Object.freeze({ __proto__: null, get BadgeContainerEditor () { return BadgeContainerEditor; } }); export { BadgeHorizontalContainerCard };