function t(t,e,i,n){var s,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(o<3?s(r):o>3?s(e,i,r):s(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r}const e=window,i=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,n=Symbol(),s=new WeakMap;class o{constructor(t,e,i){if(this._$cssResult$=!0,i!==n)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(i&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=s.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&s.set(e,t))}return t}toString(){return this.cssText}}const r=t=>new o("string"==typeof t?t:t+"",void 0,n),a=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,n)=>e+(t=>{if(!0===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.")})(i)+t[n+1]),t[0]);return new o(i,t,n)},c=i?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return r(e)})(t):t;var l;const d=window,h=d.trustedTypes,u=h?h.emptyScript:"",_=d.reactiveElementPolyfillSupport,m={toAttribute(t,e){switch(e){case Boolean:t=t?u:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){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}},p=(t,e)=>e!==t&&(e==e||t==t),g={attribute:!0,type:String,converter:m,reflect:!1,hasChanged:p},f="finalized";class y extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const n=this._$Ep(i,e);void 0!==n&&(this._$Ev.set(n,i),t.push(n))})),t}static createProperty(t,e=g){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,n=this.getPropertyDescriptor(t,i,e);void 0!==n&&Object.defineProperty(this.prototype,t,n)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(n){const s=this[t];this[e]=n,this.requestUpdate(t,s,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||g}static finalize(){if(this.hasOwnProperty(f))return!1;this[f]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(c(t))}else void 0!==t&&e.push(c(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const n=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,n)=>{i?t.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((i=>{const n=document.createElement("style"),s=e.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=i.cssText,t.appendChild(n)}))})(n,this.constructor.elementStyles),n}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=g){var n;const s=this.constructor._$Ep(t,i);if(void 0!==s&&!0===i.reflect){const o=(void 0!==(null===(n=i.converter)||void 0===n?void 0:n.toAttribute)?i.converter:m).toAttribute(e,i.type);this._$El=t,null==o?this.removeAttribute(s):this.setAttribute(s,o),this._$El=null}}_$AK(t,e){var i;const n=this.constructor,s=n._$Ev.get(t);if(void 0!==s&&this._$El!==s){const t=n.getPropertyOptions(s),o="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:m;this._$El=s,this[s]=o.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let n=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||p)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):n=!1),!this.isUpdatePending&&n&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}var v;y[f]=!0,y.elementProperties=new Map,y.elementStyles=[],y.shadowRootOptions={mode:"open"},null==_||_({ReactiveElement:y}),(null!==(l=d.reactiveElementVersions)&&void 0!==l?l:d.reactiveElementVersions=[]).push("1.6.3");const b=window,$=b.trustedTypes,w=$?$.createPolicy("lit-html",{createHTML:t=>t}):void 0,x="$lit$",S=`lit$${(Math.random()+"").slice(9)}$`,k="?"+S,E=`<${k}>`,C=document,A=()=>C.createComment(""),O=t=>null===t||"object"!=typeof t&&"function"!=typeof t,z=Array.isArray,j=t=>z(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),M="[ \t\n\f\r]",P=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,N=/-->/g,T=/>/g,U=RegExp(`>|${M}(?:([^\\s"'>=/]+)(${M}*=${M}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),D=/'/g,I=/"/g,H=/^(?:script|style|textarea|title)$/i,B=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),R=B(1),L=B(2),V=Symbol.for("lit-noChange"),F=Symbol.for("lit-nothing"),W=new WeakMap,Z=C.createTreeWalker(C,129,null,!1);function Y(t,e){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==w?w.createHTML(e):e}const q=(t,e)=>{const i=t.length-1,n=[];let s,o=2===e?"":"",r=P;for(let e=0;e"===c[0]?(r=null!=s?s:P,l=-1):void 0===c[1]?l=-2:(l=r.lastIndex-c[2].length,a=c[1],r=void 0===c[3]?U:'"'===c[3]?I:D):r===I||r===D?r=U:r===N||r===T?r=P:(r=U,s=void 0);const h=r===U&&t[e+1].startsWith("/>")?" ":"";o+=r===P?i+E:l>=0?(n.push(a),i.slice(0,l)+x+i.slice(l)+S+h):i+S+(-2===l?(n.push(void 0),e):h)}return[Y(t,o+(t[i]||"")+(2===e?"":"")),n]};class J{constructor({strings:t,_$litType$:e},i){let n;this.parts=[];let s=0,o=0;const r=t.length-1,a=this.parts,[c,l]=q(t,e);if(this.el=J.createElement(c,i),Z.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(n=Z.nextNode())&&a.length0){n.textContent=$?$.emptyScript:"";for(let i=0;i2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=F}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,n){const s=this.strings;let o=!1;if(void 0===s)t=G(this,t,e,0),o=!O(t)||t!==this._$AH&&t!==V,o&&(this._$AH=t);else{const n=t;let r,a;for(t=s[0],r=0;r{var n,s;const o=null!==(n=null==i?void 0:i.renderBefore)&&void 0!==n?n:e;let r=o._$litPart$;if(void 0===r){const t=null!==(s=null==i?void 0:i.renderBefore)&&void 0!==s?s:null;o._$litPart$=r=new Q(e.insertBefore(A(),t),t,void 0,null!=i?i:{})}return r._$AI(t),r})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return V}}lt.finalized=!0,lt._$litElement$=!0,null===(at=globalThis.litElementHydrateSupport)||void 0===at||at.call(globalThis,{LitElement:lt});const dt=globalThis.litElementPolyfillSupport;null==dt||dt({LitElement:lt}),(null!==(ct=globalThis.litElementVersions)&&void 0!==ct?ct:globalThis.litElementVersions=[]).push("3.3.3");const ht=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){customElements.define(t,e)}}})(t,e),ut=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}},_t=(t,e,i)=>{e.constructor.createProperty(i,t)};function mt(t){return(e,i)=>void 0!==i?_t(t,e,i):ut(t,e)}function pt(t){return mt({...t,state:!0})}var gt;null===(gt=window.HTMLSlotElement)||void 0===gt||gt.prototype.assignedElements;var ft={version:"Version",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",entity_not_found:"Entity state not found",missing_child:"Missing child entity",loading:"Loading..."},yt={yaml_disclaimer:"Please use yaml mode for the other options",docs:"Documentation",sections:"Sections",section:"Section",add_section:"+ Add section",add_entity:"+ Add entity",entity_editor:"Entity editor",decimals:"decimals",section_options:"Options",fields:{title:"Title",time_period_from:"Time period from",time_period_to:"Time period to",autoconfig:"Autoconfig",print_yaml:"Print auto generated config yaml",layout:"Layout",show_names:"Show names",show_icons:"Show icons",show_states:"Show states",show_units:"Show units",energy_date_selection:"Sync with energy_date_selection component",height:"Height",wide:"Wide",min_box_size:"Min box size",min_box_distance:"Min box distance",min_state:"Min state",static_scale:"Static scale",round:"Round",throttle:"Throttle",unit_prefix:"Unit prefix",entity:"Entity",type:"Type",children:"Children",name:"Name",icon:"Icon",color:"Color",unit_of_measurement:"Unit of measurement",tap_action:"Tap action",color_on_state:"Change color based on state",color_limit:"State limit for color change",color_above:"Color above limit",color_below:"Color below limit",sort_by:"Sort by",sort_dir:"Sort direction",section:{min_width:"Min width",sort_by:"Sort by",sort_dir:"Sort direction",sort_group_by_parent:"Group by parent"}},entity_types:{entity:"Entity",remaining_parent_state:"Remaining parent state",remaining_child_state:"Remaining child state",passthrough:"Passthrough"},sort_by:{none:"None",state:"State"},sort_dir:{desc:"Descending",asc:"Ascending"},layout:{auto:"Auto",vertical:"Vertical",horizontal:"Horizontal"}},vt={common:ft,editor:yt},bt={version:"Verze",invalid_configuration:"Nesprávná konfigurace",show_warning:"Zobrazit upozornění",entity_not_found:"Stav entity sa nenašel",missing_child:"Chybí podřazená entita",loading:"Načítaní..."},$t={yaml_disclaimer:"Pro ostatní možnosti použijte režim yaml",docs:"Dokumentace",sections:"Oddíly",section:"Oddíl",add_section:"+ Přidat oddíl",add_entity:"+ Přidat entitu",entity_editor:"Editor entity",decimals:"desetinná místa",section_options:"Možnosti",fields:{autoconfig:"Autokonfig",print_yaml:"Ukáže automaticky generovaný konfigurační yaml",layout:"Rozložení",show_names:"Zobrazit názvy",show_icons:"Zobrazit ikony",show_states:"Zobrazit stavy",show_units:"Zobrazit jednotky",energy_date_selection:"Synchronizace s komponentem energy_date_selection",height:"Výška",wide:"Šírka",min_box_size:"Min. výška boxu",min_box_distance:"Minimální vzdálenost boxu",min_state:"Min stav",static_scale:"Statická míra",round:"Zaokrouhlit",throttle:"Plyn",unit_prefix:"Předpona jednotky",entity:"Entita",type:"Typ",children:"Podřazený",name:"Název",icon:"Ikona",color:"Barva",unit_of_measurement:"Jednotky meření",tap_action:"Klikněte na akci",color_on_state:"Zmeňte barvu podle stavu",color_limit:"Limit pro změnu barvy",color_above:"Barva nad limitem",color_below:"Barva pod limitem",sort_by:"Třídit podle",sort_dir:"Směr třídění",section:{min_width:"Min. šířka",sort_by:"Třídit podle",sort_dir:"Směr řazení",sort_group_by_parent:"Skupina podle nadřazených"}},entity_types:{entity:"Entita",remaining_parent_state:"Zbývající nadřazený stav",remaining_child_state:"Zbývající podřazený stav",passthrough:"Přejít přes"},sort_by:{none:"Nic",state:"Stav"},sort_dir:{desc:"Sestupně",asc:"Vzestupně"},layout:{auto:"Auto",vertical:"Vertikálně",horizontal:"Horizontálně"}},wt={common:bt,editor:$t},xt={version:"Verzia",invalid_configuration:"Nesprávna konfigurácia",show_warning:"Zobraziť upozornenie",entity_not_found:"Stav entity sa nenašiel",missing_child:"Chýbajúca podriadená entita",loading:"Načítanie..."},St={yaml_disclaimer:"Pre ostatné možnosti použite režim yaml",docs:"Documentácia",sections:"Oddiely",section:"Oddiel",add_section:"+ Pridať oddiel",add_entity:"+ Pridať entitu",entity_editor:"Editor entity",decimals:"desatinné miesta",section_options:"Možnosti",fields:{autoconfig:"Autokonfig",print_yaml:"Vytlačte automaticky generovanú konfiguráciu yaml",layout:"Rozloženie",show_names:"Zobraziť názvy",show_icons:"Zobraziť ikony",show_states:"Zobraziť stavy",show_units:"Zobraziť jednotky",energy_date_selection:"Synchronizácia s komponentom energy_date_selection",height:"Výška",wide:"Šírka",min_box_size:"Min. výška boxu",min_box_distance:"Minimálna vzdialenosť boxu",min_state:"Min stav",static_scale:"Statická mierka",round:"Zaokrúhliť",throttle:"Plyn",unit_prefix:"Predpona jednotky",entity:"Entita",type:"Typ",children:"Podriadený",name:"Názov",icon:"Ikona",color:"Farba",unit_of_measurement:"Jednotky merania",tap_action:"Klepnite na akciu",color_on_state:"Zmeňte farbu podľa stavu",color_limit:"Štátny limit pre zmenu farby",color_above:"Farba nad limitom",color_below:"Farba pod limitom",sort_by:"Triediť podľa",sort_dir:"Smer triedenia",section:{min_width:"Min. šírka",sort_by:"Triediť podľa",sort_dir:"Smer zoradenia",sort_group_by_parent:"Skupina podľa rodiča"}},entity_types:{entity:"Entita",remaining_parent_state:"Zostávajúci rodičovský stav",remaining_child_state:"Zostávajúci podriadený stav",passthrough:"Prejsť cez"},sort_by:{none:"Nič",state:"Stav"},sort_dir:{desc:"Zostupne",asc:"Vzostupne"},layout:{auto:"Auto",vertical:"Vertikálne",horizontal:"Horizontálne"}},kt={common:xt,editor:St},Et={version:"Versie",invalid_configuration:"Ongeldige configuratie",show_warning:"Toon waarschuwing",entity_not_found:"Entiteit niet gevonden",missing_child:"Ontbrekende onderliggende entiteit",loading:"Laden..."},Ct={},At={common:Et,editor:Ct},Ot={version:"Versão",invalid_configuration:"Configuração inválida",show_warning:"Mostar Aviso",entity_not_found:"Estado da entidade não encontrado",missing_child:"Entidade filho não encontrada",loading:"Carregando..."},zt={yaml_disclaimer:"Por favor, use o modo yaml para as outras opções",docs:"Documentação",sections:"Seções",section:"Seção",add_section:"+ Add seção",add_entity:"+ Adicionar entidade",entity_editor:"Editor de entidade",decimals:"decimais",section_options:"Opções",fields:{autoconfig:"Auto-configurar",print_yaml:"Imprimir yaml da configuração gerada automaticamente",layout:"Layout",show_names:"Mostrar nomes",show_icons:"Mostrar ícones",show_states:"Mostrar estados",show_units:"Mostrar unidades",energy_date_selection:"Sincronizar com o componente energy_date_selection",height:"Altura",wide:"Largura",min_box_size:"Tamanho mínimo da caixa",min_box_distance:"Distância mínima da caixa",min_state:"Estado mínimo",static_scale:"Escala estática",round:"Arredondar",throttle:"Acelerador",unit_prefix:"Prefixo da unidade",entity:"Entidade",type:"Tipo",children:"Filho",name:"Nome",icon:"Ícone",color:"Cor",unit_of_measurement:"Unidade de medida",tap_action:"Ação ao tocar",color_on_state:"Alterar cor com base no estado",color_limit:"Limite de estado para mudança de cor",color_above:"Cor acima do limite",color_below:"Cor abaixo do limite",sort_by:"Ordenar por",sort_dir:"Direção de ordenação",section:{min_width:"Largura mínima",sort_by:"Ordenar por",sort_dir:"Direção de ordenação",sort_group_by_parent:"Agrupar por pai"}},entity_types:{entity:"Entidade",remaining_parent_state:"Restante do estado pai",remaining_child_state:"Restante do estado filho",passthrough:"Passagem"},sort_by:{none:"Nenhum",state:"Estado"},sort_dir:{desc:"Descendente",asc:"Ascendente"},layout:{auto:"Automático",vertical:"Vertical",horizontal:"Horizontal"}},jt={common:Ot,editor:zt};const Mt={en:Object.freeze({__proto__:null,common:ft,editor:yt,default:vt}),cz:Object.freeze({__proto__:null,common:bt,editor:$t,default:wt}),sk:Object.freeze({__proto__:null,common:xt,editor:St,default:kt}),nl:Object.freeze({__proto__:null,common:Et,editor:Ct,default:At}),pt:Object.freeze({__proto__:null,common:Ot,editor:zt,default:jt})};function Pt(t,e="",i=""){const n=(localStorage.getItem("selectedLanguage")||"en").replace(/['"]+/g,"").replace("-","_");let s;try{s=t.split(".").reduce(((t,e)=>t[e]),Mt[n])}catch(e){s=t.split(".").reduce(((t,e)=>t[e]),Mt.en)}return void 0===s&&(s=t.split(".").reduce(((t,e)=>t&&t[e]),Mt.en)),""!==e&&""!==i&&(s=s.replace(e,i)),s}var Nt,Tt;function Ut(){return(Ut=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},Bt=["closed","locked","off"],Rt=function(t,e,i,n){n=n||{},i=null==i?{}:i;var s=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return s.detail=i,t.dispatchEvent(s),s},Lt=new Set(["call-service","divider","section","weblink","cast","select"]),Vt={alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"},Ft={alert:"mdi:alert",automation:"mdi:playlist-play",calendar:"mdi:calendar",camera:"mdi:video",climate:"mdi:thermostat",configurator:"mdi:settings",conversation:"mdi:text-to-speech",device_tracker:"mdi:account",fan:"mdi:fan",group:"mdi:google-circles-communities",history_graph:"mdi:chart-line",homeassistant:"mdi:home-assistant",homekit:"mdi:home-automation",image_processing:"mdi:image-filter-frames",input_boolean:"mdi:drawing",input_datetime:"mdi:calendar-clock",input_number:"mdi:ray-vertex",input_select:"mdi:format-list-bulleted",input_text:"mdi:textbox",light:"mdi:lightbulb",mailbox:"mdi:mailbox",notify:"mdi:comment-alert",person:"mdi:account",plant:"mdi:flower",proximity:"mdi:apple-safari",remote:"mdi:remote",scene:"mdi:google-pages",script:"mdi:file-document",sensor:"mdi:eye",simple_alarm:"mdi:bell",sun:"mdi:white-balance-sunny",switch:"mdi:flash",timer:"mdi:timer",updater:"mdi:cloud-upload",vacuum:"mdi:robot-vacuum",water_heater:"mdi:thermometer",weblink:"mdi:open-in-new"};function Wt(t,e){if(t in Ft)return Ft[t];switch(t){case"alarm_control_panel":switch(e){case"armed_home":return"mdi:bell-plus";case"armed_night":return"mdi:bell-sleep";case"disarmed":return"mdi:bell-outline";case"triggered":return"mdi:bell-ring";default:return"mdi:bell"}case"binary_sensor":return e&&"off"===e?"mdi:radiobox-blank":"mdi:checkbox-marked-circle";case"cover":return"closed"===e?"mdi:window-closed":"mdi:window-open";case"lock":return e&&"unlocked"===e?"mdi:lock-open":"mdi:lock";case"media_player":return e&&"off"!==e&&"idle"!==e?"mdi:cast-connected":"mdi:cast";case"zwave":switch(e){case"dead":return"mdi:emoticon-dead";case"sleeping":return"mdi:sleep";case"initializing":return"mdi:timer-sand";default:return"mdi:z-wave"}default:return console.warn("Unable to find icon for domain "+t+" ("+e+")"),"mdi:bookmark"}}var Zt=function(t){Rt(window,"haptic",t)},Yt=function(t,e){return function(t,e,i){void 0===i&&(i=!0);var n,s=Dt(e),o="group"===s?"homeassistant":s;switch(s){case"lock":n=i?"unlock":"lock";break;case"cover":n=i?"open_cover":"close_cover";break;default:n=i?"turn_on":"turn_off"}return t.callService(o,n,{entity_id:e})}(t,e,Bt.includes(t.states[e].state))},qt={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Jt={binary_sensor:function(t,e){var i="off"===t;switch(null==e?void 0:e.attributes.device_class){case"battery":return i?"mdi:battery":"mdi:battery-outline";case"battery_charging":return i?"mdi:battery":"mdi:battery-charging";case"cold":return i?"mdi:thermometer":"mdi:snowflake";case"connectivity":return i?"mdi:server-network-off":"mdi:server-network";case"door":return i?"mdi:door-closed":"mdi:door-open";case"garage_door":return i?"mdi:garage":"mdi:garage-open";case"power":case"plug":return i?"mdi:power-plug-off":"mdi:power-plug";case"gas":case"problem":case"safety":case"tamper":return i?"mdi:check-circle":"mdi:alert-circle";case"smoke":return i?"mdi:check-circle":"mdi:smoke";case"heat":return i?"mdi:thermometer":"mdi:fire";case"light":return i?"mdi:brightness-5":"mdi:brightness-7";case"lock":return i?"mdi:lock":"mdi:lock-open";case"moisture":return i?"mdi:water-off":"mdi:water";case"motion":return i?"mdi:walk":"mdi:run";case"occupancy":case"presence":return i?"mdi:home-outline":"mdi:home";case"opening":return i?"mdi:square":"mdi:square-outline";case"running":return i?"mdi:stop":"mdi:play";case"sound":return i?"mdi:music-note-off":"mdi:music-note";case"update":return i?"mdi:package":"mdi:package-up";case"vibration":return i?"mdi:crop-portrait":"mdi:vibrate";case"window":return i?"mdi:window-closed":"mdi:window-open";default:return i?"mdi:radiobox-blank":"mdi:checkbox-marked-circle"}},cover:function(t){var e="closed"!==t.state;switch(t.attributes.device_class){case"garage":return e?"mdi:garage-open":"mdi:garage";case"door":return e?"mdi:door-open":"mdi:door-closed";case"shutter":return e?"mdi:window-shutter-open":"mdi:window-shutter";case"blind":return e?"mdi:blinds-open":"mdi:blinds";case"window":return e?"mdi:window-open":"mdi:window-closed";default:return Wt("cover",t.state)}},sensor:function(t){var e=t.attributes.device_class;if(e&&e in qt)return qt[e];if("battery"===e){var i=Number(t.state);if(isNaN(i))return"mdi:battery-unknown";var n=10*Math.round(i/10);return n>=100?"mdi:battery":n<=0?"mdi:battery-alert":"hass:battery-"+n}var s=t.attributes.unit_of_measurement;return"°C"===s||"°F"===s?"mdi:thermometer":Wt("sensor")},input_datetime:function(t){return t.attributes.has_date?t.attributes.has_time?Wt("input_datetime"):"mdi:calendar":"mdi:clock"}},Gt=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=Dt(t.entity_id);return e in Jt?Jt[e](t):Wt(e,t.state)};const Kt={m:.001,k:1e3,M:1e6,G:1e9,T:1e12},Qt=15,Xt=8.15,te={type:"entity"},ee=35.31,ie={type:"custom:ha-sankey-chart",layout:"auto",height:200,unit_prefix:"",round:0,convert_units_to:"",co2_intensity_entity:"sensor.co2_signal_co2_intensity",min_box_size:3,min_box_distance:5,min_state:0,show_states:!0,show_units:!0,sections:[]};function ne(t){if(null===t||!0===t||!1===t)return NaN;var e=Number(t);return isNaN(e)?e:e<0?Math.ceil(e):Math.floor(e)}function se(t,e){if(e.length1?"s":"")+" required, but only "+e.length+" present")}function oe(t){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},oe(t)}function re(t){se(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||"object"===oe(t)&&"[object Date]"===e?new Date(t.getTime()):"number"==typeof t||"[object Number]"===e?new Date(t):("string"!=typeof t&&"[object String]"!==e||"undefined"==typeof console||(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn((new Error).stack)),new Date(NaN))}function ae(t,e){se(2,arguments);var i=re(t),n=ne(e);return isNaN(n)?new Date(NaN):n?(i.setDate(i.getDate()+n),i):i}function ce(t,e){se(2,arguments);var i=re(t),n=ne(e);if(isNaN(n))return new Date(NaN);if(!n)return i;var s=i.getDate(),o=new Date(i.getTime());return o.setMonth(i.getMonth()+n+1,0),s>=o.getDate()?o:(i.setFullYear(o.getFullYear(),o.getMonth(),s),i)}function le(t,e){se(2,arguments);var i=re(t).getTime(),n=ne(e);return new Date(i+n)}var de=36e5;var he={};function ue(){return he}function _e(t){var e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return e.setUTCFullYear(t.getFullYear()),t.getTime()-e.getTime()}function me(t){se(1,arguments);var e=re(t);return e.setHours(0,0,0,0),e}var pe=864e5;var ge=6e4;function fe(t,e){var i=t.getFullYear()-e.getFullYear()||t.getMonth()-e.getMonth()||t.getDate()-e.getDate()||t.getHours()-e.getHours()||t.getMinutes()-e.getMinutes()||t.getSeconds()-e.getSeconds()||t.getMilliseconds()-e.getMilliseconds();return i<0?-1:i>0?1:i}function ye(t,e){se(2,arguments);var i=re(t),n=re(e),s=fe(i,n),o=Math.abs(function(t,e){se(2,arguments);var i=me(t),n=me(e),s=i.getTime()-_e(i),o=n.getTime()-_e(n);return Math.round((s-o)/pe)}(i,n));i.setDate(i.getDate()-s*o);var r=s*(o-Number(fe(i,n)===-s));return 0===r?0:r}function ve(t,e,i,n=!1){const s=Math.max(0,e)||0;if(!i||"monetary"==i)return{state:s,unit_of_measurement:i};const o=function(t){const e=t.replace("²","").replace("³","");return e.length>1&&Object.keys(Kt).find((e=>0===t.indexOf(e)))||""}(i),r=Kt[o]||1;if("auto"===t)if(n){const i=Math.abs(e*r);t=i<1?"m":i>=1e3&&i<1e6?"k":i>=1e6&&i<1e9?"M":i>=1e9&&i<1e12?"G":i>=1e12?"T":""}else t="";const a=Kt[t]||1;return r===a?{state:s,unit_of_measurement:i}:{state:s*r/a,unit_of_measurement:o?i.replace(o,t):t+i}}function be(t){return"string"==typeof t?t:t.entity_id}function $e(t,e){let i=Object.assign({sections:[]},(n=t,JSON.parse(JSON.stringify(n))));var n;const{autoconfig:s}=t;(s||"object"==typeof s)&&(i=Object.assign(Object.assign({energy_date_selection:!i.time_period_from,unit_prefix:"k",round:1},i),{sections:[]}));const o=i.sections.map((t=>Object.assign(Object.assign({},t),{entities:t.entities.map((t=>"string"==typeof t?Object.assign(Object.assign({},te),{children:[],entity_id:t}):Object.assign(Object.assign(Object.assign({},te),{children:[]}),t)))})));we(o);return Object.assign(Object.assign(Object.assign(Object.assign({},ie),{gas_co2_intensity:e?66.6*ee:66.6}),i),{min_state:i.min_state?Math.abs(i.min_state):0,sections:o})}function we(t){t.forEach(((e,i)=>{e.entities.forEach((e=>{e.children&&e.children.length&&e.children.forEach((e=>{for(let n=i+1;nbe(t)===be(e)));if(s){if(n>i+1)for(let e=i+1;e"passthrough"===t.config.type?[t.entity_id]:t.config.children.map(be))),s=(t,e,n)=>{let s=i.findIndex((e=>e.includes(t.entity_id))),o=i.findIndex((t=>t.includes(e.entity_id)));return-1===s&&(s=i.length),-1===o&&(o=i.length),so?1:n(t,e)};"desc"===n?e.sort(((t,e)=>s(t,e,((t,e)=>t.state>e.state?-1:t.states(t,e,((t,e)=>t.statee.state?1:0))))}return e}async function Se(t,e,i){const n={type:"error",error:t,origConfig:e};let s;const o=window.loadCardHelpers?window.loadCardHelpers():void 0;return s=o?(await o).createCardElement(n):function(t,e){void 0===e&&(e=!1);var i=function(t,e){return n("hui-error-card",{type:"error",error:t,config:e})},n=function(t,e){var n=window.document.createElement(t);try{if(!n.setConfig)return;n.setConfig(e)}catch(n){return console.error(t,n),i(n.message,e)}return n};if(!t||"object"!=typeof t||!e&&!t.type)return i("No type defined",t);var s=t.type;if(s&&s.startsWith("custom:"))s=s.substr(7);else if(e)if(Lt.has(s))s="hui-"+s+"-row";else{if(!t.entity)return i("Invalid config given.",t);var o=t.entity.split(".",1)[0];s="hui-"+(Vt[o]||"text")+"-entity-row"}else s="hui-"+s+"-card";if(customElements.get(s))return n(s,t);var r=i("Custom element doesn't exist: "+t.type+".",t);r.style.display="None";var a=setTimeout((function(){r.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(a),Rt(r,"ll-rebuild",{},r)})),r}(n),i&&(s.hass=i),R`${s}`}function ke(t,e="now"){const i=new Date;function n(t){if("now"===t)return i;const e=t.match(/^now(-|\+)?(\d+)?([smhdwMy])?(\/(d|w|M|y))?$/);if(!e)throw new Error(`Invalid time format: ${t}`);const[,n,s,o,,r]=e;let a=new Date(i);if(s&&o){const t=parseInt(s,10)*("-"===n?-1:1);switch(o){case"s":a=function(t,e){return se(2,arguments),le(t,1e3*ne(e))}(a,t);break;case"m":a=function(t,e){return se(2,arguments),le(t,ne(e)*ge)}(a,t);break;case"h":a=function(t,e){return se(2,arguments),le(t,ne(e)*de)}(a,t);break;case"d":a=ae(a,t);break;case"w":a=function(t,e){return se(2,arguments),ae(t,7*ne(e))}(a,t);break;case"M":a=ce(a,t);break;case"y":a=function(t,e){return se(2,arguments),ce(t,12*ne(e))}(a,t)}}if(r)switch(r){case"d":a=me(a);break;case"w":a=function(t,e){var i,n,s,o,r,a,c,l;se(1,arguments);var d=ue(),h=ne(null!==(i=null!==(n=null!==(s=null!==(o=null==e?void 0:e.weekStartsOn)&&void 0!==o?o:null==e||null===(r=e.locale)||void 0===r||null===(a=r.options)||void 0===a?void 0:a.weekStartsOn)&&void 0!==s?s:d.weekStartsOn)&&void 0!==n?n:null===(c=d.locale)||void 0===c||null===(l=c.options)||void 0===l?void 0:l.weekStartsOn)&&void 0!==i?i:0);if(!(h>=0&&h<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var u=re(t),_=u.getDay(),m=(_{class i extends e{connectedCallback(){super.connectedCallback(),this.__checkSubscribed()}disconnectedCallback(){super.disconnectedCallback(),this.hassUnsubscribe()}updated(t){super.updated(t),t.has("hass")&&this.__checkSubscribed()}resetSubscriptions(){this.hassUnsubscribe(),this.__checkSubscribed()}hassSubscribe(){return[]}hassUnsubscribe(){if(this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then((t=>t())):t()}this.__unsubs=void 0}}__checkSubscribed(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&(this.__unsubs=this.hassSubscribe())}}return t([mt({attribute:!1})],i.prototype,"hass",void 0),i},Ce=1,Ae=2,Oe=t=>(...e)=>({_$litDirective$:t,values:e});class ze{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)}}const je="important",Me=" !"+je,Pe=Oe(class extends ze{constructor(t){var e;if(super(t),t.type!==Ce||"style"!==t.name||(null===(e=t.strings)||void 0===e?void 0:e.length)>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce(((e,i)=>{const n=t[i];return null==n?e:e+`${i=i.includes("-")?i:i.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${n};`}),"")}update(t,[e]){const{style:i}=t.element;if(void 0===this.ht){this.ht=new Set;for(const t in e)this.ht.add(t);return this.render(e)}this.ht.forEach((t=>{null==e[t]&&(this.ht.delete(t),t.includes("-")?i.removeProperty(t):i[t]="")}));for(const t in e){const n=e[t];if(null!=n){this.ht.add(t);const e="string"==typeof n&&n.endsWith(Me);t.includes("-")||e?i.setProperty(t,e?n.slice(0,-11):n,e?je:""):i[t]=n}}return V}}),Ne=Oe(class extends ze{constructor(t){var e;if(super(t),t.type!==Ce||"class"!==t.name||(null===(e=t.strings)||void 0===e?void 0:e.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((e=>t[e])).join(" ")+" "}update(t,[e]){var i,n;if(void 0===this.it){this.it=new Set,void 0!==t.strings&&(this.nt=new Set(t.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in e)e[t]&&!(null===(i=this.nt)||void 0===i?void 0:i.has(t))&&this.it.add(t);return this.render(e)}const s=t.element.classList;this.it.forEach((t=>{t in e||(s.remove(t),this.it.delete(t))}));for(const t in e){const i=!!e[t];i===this.it.has(t)||(null===(n=this.nt)||void 0===n?void 0:n.has(t))||(i?(s.add(t),this.it.add(t)):(s.remove(t),this.it.delete(t)))}return V}}),{I:Te}=ot,Ue=()=>document.createComment(""),De=(t,e,i)=>{var n;const s=t._$AA.parentNode,o=void 0===e?t._$AB:e._$AA;if(void 0===i){const e=s.insertBefore(Ue(),o),n=s.insertBefore(Ue(),o);i=new Te(e,n,t,t.options)}else{const e=i._$AB.nextSibling,r=i._$AM,a=r!==t;if(a){let e;null===(n=i._$AQ)||void 0===n||n.call(i,t),i._$AM=t,void 0!==i._$AP&&(e=t._$AU)!==r._$AU&&i._$AP(e)}if(e!==o||a){let t=i._$AA;for(;t!==e;){const e=t.nextSibling;s.insertBefore(t,o),t=e}}}return i},Ie=(t,e,i=t)=>(t._$AI(e,i),t),He={},Be=t=>{var e;null===(e=t._$AP)||void 0===e||e.call(t,!1,!0);let i=t._$AA;const n=t._$AB.nextSibling;for(;i!==n;){const t=i.nextSibling;i.remove(),i=t}},Re=(t,e)=>{var i,n;const s=t._$AN;if(void 0===s)return!1;for(const t of s)null===(n=(i=t)._$AO)||void 0===n||n.call(i,e,!1),Re(t,e);return!0},Le=t=>{let e,i;do{if(void 0===(e=t._$AM))break;i=e._$AN,i.delete(t),t=e}while(0===(null==i?void 0:i.size))},Ve=t=>{for(let e;e=t._$AM;t=e){let i=e._$AN;if(void 0===i)e._$AN=i=new Set;else if(i.has(t))break;i.add(t),Ze(e)}};function Fe(t){void 0!==this._$AN?(Le(this),this._$AM=t,Ve(this)):this._$AM=t}function We(t,e=!1,i=0){const n=this._$AH,s=this._$AN;if(void 0!==s&&0!==s.size)if(e)if(Array.isArray(n))for(let t=i;t{var e,i,n,s;t.type==Ae&&(null!==(e=(n=t)._$AP)&&void 0!==e||(n._$AP=We),null!==(i=(s=t)._$AQ)&&void 0!==i||(s._$AQ=Fe))};class Ye extends ze{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,i){super._$AT(t,e,i),Ve(this),this.isConnected=t._$AU}_$AO(t,e=!0){var i,n;t!==this.isConnected&&(this.isConnected=t,t?null===(i=this.reconnected)||void 0===i||i.call(this):null===(n=this.disconnected)||void 0===n||n.call(this)),e&&(Re(this,t),Le(this))}setValue(t){if((t=>void 0===t.strings)(this._$Ct))this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}class qe{constructor(t){this.G=t}disconnect(){this.G=void 0}reconnect(t){this.G=t}deref(){return this.G}}class Je{constructor(){this.Y=void 0,this.Z=void 0}get(){return this.Y}pause(){var t;null!==(t=this.Y)&&void 0!==t||(this.Y=new Promise((t=>this.Z=t)))}resume(){var t;null===(t=this.Z)||void 0===t||t.call(this),this.Y=this.Z=void 0}}const Ge=t=>!(t=>null===t||"object"!=typeof t&&"function"!=typeof t)(t)&&"function"==typeof t.then,Ke=1073741823;const Qe=Oe(class extends Ye{constructor(){super(...arguments),this._$C_t=Ke,this._$Cwt=[],this._$Cq=new qe(this),this._$CK=new Je}render(...t){var e;return null!==(e=t.find((t=>!Ge(t))))&&void 0!==e?e:V}update(t,e){const i=this._$Cwt;let n=i.length;this._$Cwt=e;const s=this._$Cq,o=this._$CK;this.isConnected||this.disconnected();for(let t=0;tthis._$C_t);t++){const r=e[t];if(!Ge(r))return this._$C_t=t,r;t{for(;o.get();)await o.get();const e=s.deref();if(void 0!==e){const i=e._$Cwt.indexOf(r);i>-1&&iRt(t,"hass-notification",e),ei=async(t,e,i,n)=>{var s,o,r,a;let c=i.tap_action;if("double_tap"===n&&i.double_tap_action?c=i.double_tap_action:"hold"===n&&i.hold_action&&(c=i.hold_action),c||(c={action:"more-info"}),!c.confirmation||c.confirmation.exemptions&&c.confirmation.exemptions.some((t=>t.user===e.user.id))||(Zt("warning"),confirm(c.confirmation.text||e.localize("ui.panel.lovelace.cards.actions.action_confirmation","action",e.localize("ui.panel.lovelace.editor.action-editor.actions."+c.action)||c.action))))switch(c.action){case"more-info":Rt(t,"hass-more-info",{entityId:null!==(r=null!==(s=c.entity)&&void 0!==s?s:null===(o=c.data)||void 0===o?void 0:o.entity_id)&&void 0!==r?r:i.entity_id});break;case"navigate":c.navigation_path?function(t,e,i){void 0===i&&(i=!1),i?history.replaceState(null,"",e):history.pushState(null,"",e),Rt(window,"location-changed",{replace:i})}(0,c.navigation_path):(ti(t,{message:e.localize("ui.panel.lovelace.cards.actions.no_navigation_path")}),Zt("failure"));break;case"url":c.url_path?window.open(c.url_path):(ti(t,{message:e.localize("ui.panel.lovelace.cards.actions.no_url")}),Zt("failure"));break;case"toggle":Yt(e,i.entity_id),Zt("light");break;case"call-service":{if(!c.service)return ti(t,{message:e.localize("ui.panel.lovelace.cards.actions.no_service")}),void Zt("failure");const[i,n]=c.service.split(".",2);e.callService(i,n,null!==(a=c.data)&&void 0!==a?a:c.service_data,c.target),Zt("light");break}case"fire-dom-event":Rt(t,"ll-custom",c);break;case"zoom":if(t.zoomEntity===i){t.zoomEntity=void 0;break}t.zoomEntity=i}};function ii(t){const{boxes:e,size:i}=t.section;return e.filter((t=>t.children.length>0||"passthrough"===t.config.type)).map(((e,n)=>{const s=t.nextSection.boxes.filter((t=>e.children.some((e=>be(e)===t.entity_id))||"passthrough"===e.config.type&&e.entity_id===t.entity_id)),o=function(t,e,i,n){let s=0,o=0;const r=n.get(t.config);return e.map((e=>{let n=null==r?void 0:r.filter((t=>t.child.entity_id===e.entity_id));if(!(null==n?void 0:n.length)&&(n=i.filter((i=>i.passthroughs.includes(e)||i.passthroughs.includes(t.config))),!n.length))throw new Error(`Missing connection: ${t.entity_id} - ${e.entity_id}`);if(o=n.reduce(((t,e)=>t+e.state),0),o<=0)return{state:o};const a=s/t.state*t.size+t.top;s+=o;const c=Math.max(o/t.state*t.size,0),l=e.connectedParentState/e.state*e.size+e.top,d=Math.max(o/e.state*e.size,0);return e.connectedParentState+=o,{startY:a,startSize:c,startColor:t.color,endY:l,endSize:d,endColor:e.color,state:o,highlighted:n.some((t=>t.highlighted))}}))}(e,s,t.allConnections,t.connectionsByParent).filter((t=>t.state>0));return L`${o.map(((e,i)=>L``))}${o.map(((e,s)=>{let o=[["M",0,e.startY],["C",50,e.startY],["",50,e.endY],["",100,e.endY],["L",100,e.endY+e.endSize],["C",50,e.endY+e.endSize],["",50,e.startY+e.startSize],["",0,e.startY+e.startSize]];return t.vertical&&(o=o.map((t=>[t[0],i-t[2],t[1]]))),L``}))}`}))}function ni(t){const{show_icons:e}=t.config,{boxes:i,spacerSize:n,config:{min_width:s},size:o}=t.section,r=t.nextSection&&i.some((t=>t.children.length>0||"passthrough"===t.config.type)),a=t.vertical?`0 0 ${o} 100`:`0 0 100 ${o}`,c=s&&!t.vertical?s+"px":void 0;return R`
${r?R`
${ii(t)}
`:null} ${i.map((i=>{const{entity:s,extraSpacers:o}=i;"auto"===t.config.unit_prefix&&(i=Object.assign(Object.assign({},i),ve(t.config.unit_prefix,i.state,i.unit_of_measurement,!0)));const r=function(t,e,i,n){let s,o=e;do{s=t.toFixed(o++)}while(/^[0\.,]*$/.test(s)&&o<20);return It(parseFloat(s),i,n?{style:"currency",currency:n,minimumFractionDigits:o-1,maximumFractionDigits:o-1}:{minimumFractionDigits:0,maximumFractionDigits:o-1})}(i.state,t.config.round,t.locale,t.config.monetary_unit),a="passthrough"!==i.config.type,c=i.config.name||s.attributes.friendly_name||"",l=i.config.icon||Gt(s),d=t.vertical?"width":"height";return R`${i.top>0?R`
`:null} ${o?R`
`:null}
${e&&a?R``:null}
${function(t,e,i,n,s,o){const{show_names:r,show_states:a,show_units:c}=e;if("passthrough"===t.config.type||!r&&!a)return null;const l=t.size+s-1,d={lineHeight:Qt+"px"},h={};if(o){d.width=l+"px";const e=(i+(c?t.unit_of_measurement:"")).length*Xt;if(e>l){const t=l/e;d.fontSize=`${t}em`,d.lineHeight=`${t}em`}if(r){const t=Math.max(...n.split(/[\s]+/).map((t=>t.length))),e=t*Xt;if(e>l){const t=l/e;h.fontSize=`${t}rem`,h.lineHeight=`${t}rem`}}}else{if(lt)).length;t>1&&(h.whiteSpace="pre",d.fontSize?(h.fontSize=1/t+.1+"rem",h.lineHeight=1/t+.1+"rem"):l${a?R`${i}${c?R`${t.unit_of_measurement}`:null}`:null} ${r?R`${o?null:R` `}${t.config.url?R`${n}`:R`${n}`}`:null}
`}(i,t.config,r,c,n,t.vertical)}
${o?R`
`:null}`}))}`}function si(t,e,i,n){var s;const o="parents"===e?t.parents_sum:t.children_sum,r=new Map,{state:a,last_updated:c}=n(t),l=[],d="children"===e?"child":"parent",h=null!==(s=i.reduce(((t,e)=>(l.push(e[d]),t+n(e[d]).state)),0))&&void 0!==s?s:0,{should_be:u}=o;if("equal"===u&&h!==a||"equal_or_more"===u&&ha){const{reconcile_to:e}=o;let i=a;switch(e){case"min":i=Math.min(h,a);break;case"max":i=Math.max(h,a);break;case"mean":i=(h+a)/2;break;case"latest":const t=new Date(c).getTime();l.some((e=>new Date(n(e).last_updated).getTime()>t))&&(i=h)}r.set(t,i),l.forEach((t=>{r.set(t,n(t).state/h*i)}))}return r}let oi=class extends lt{constructor(){super(...arguments),this.sections=[],this.entityIds=[],this.connections=[],this.connectionsByParent=new Map,this.connectionsByChild=new Map,this.reconciledStates=new Map,this.statePerPixel=0,this.entityStates=new Map,this.highlightedEntities=[],this.lastUpdate=0,this.vertical=!1,this.width=0,this.randomColors=new Map}shouldUpdate(t){if(!this.config)return!1;if(t.has("config")||t.has("forceUpdateTs")||t.has("highlightedEntities")||t.has("zoomEntity")||t.has("width"))return!0;const e=Date.now();if(this.config.throttle&&e-this.lastUpdate{t===this.lastUpdate&&this.requestUpdate()}),e-this.lastUpdate),!1}const i=t.get("states");return!!i&&(!Object.keys(i).length||this.entityIds.some((t=>i[t]!==this.states[t]&&i[t].state!==this.states[t].state)))}willUpdate(t){this.vertical=function(t,e){if("auto"===t.layout)return e{var i;return(null!==(i=e.min_width)&&void 0!==i?i:150)+t}),0);return"vertical"===t.layout}(this.config,this.width),this.entityIds.length&&!t.has("config")||(this.entityIds=[],this.connections=[],this.connectionsByParent.clear(),this.connectionsByChild.clear(),this.reconciledStates.clear(),this.config.sections.forEach((({entities:t},e)=>{t.forEach((t=>{if("entity"===t.type)this.entityIds.push(t.entity_id);else if("passthrough"===t.type)return;t.children.forEach((i=>{var n;const s=[],o=be(i);let r=t;for(let t=e+1;tt.entity_id===o)),!r)throw this.error=new Error(Pt("common.missing_child")+" "+be(i)),this.error;if("passthrough"!==r.type)break;s.push(r)}const a={parent:t,child:r,state:0,prevParentState:0,prevChildState:0,ready:!1,passthroughs:s};this.connections.push(a),this.connectionsByParent.has(t)||this.connectionsByParent.set(t,[]),this.connectionsByParent.get(t).push(a),this.connectionsByChild.has(r)||this.connectionsByChild.set(r,[]),this.connectionsByChild.get(r).push(a)}))}))})))}_calcConnections(){const t=new Map,e=new Map;this.connections.forEach((t=>{t.ready=!1,t.calculating=!1})),this.connections.forEach((i=>this._calcConnection(i,t,e)))}_calcConnection(t,e,i,n){var s,o,r,a,c,l,d,h,u;if(t.ready&&!n)return;const{parent:_,child:m}=t;t.calculating||(t.calculating=!0,[_,m].forEach((n=>{var s,o;"remaining_child_state"===n.type?null===(s=this.connectionsByParent.get(n))||void 0===s||s.forEach((n=>{var s;n.ready||null===(s=this.connectionsByChild.get(n.child))||void 0===s||s.forEach((n=>{n===t||n.calculating||this._calcConnection(n,e,i)}))})):"remaining_parent_state"===n.type&&(null===(o=this.connectionsByChild.get(n))||void 0===o||o.forEach((n=>{var s;n.ready||null===(s=this.connectionsByParent.get(n.parent))||void 0===s||s.forEach((n=>{n===t||n.calculating||this._calcConnection(n,e,i)}))})))})));const p=null!==(s=this._getMemoizedState(_).state)&&void 0!==s?s:0;t.prevParentState=null!==(o=i.get(_))&&void 0!==o?o:0;const g=Math.max(0,p-t.prevParentState),f=null!==(r=this._getMemoizedState(m).state)&&void 0!==r?r:0;t.prevChildState=null!==(a=e.get(m))&&void 0!==a?a:0;const y=Math.max(0,f-t.prevChildState);if(g&&y){const n=_.children.find((t=>be(t)===m.entity_id));if("object"==typeof n&&n.connection_entity_id){const e=null!==(c=this._getMemoizedState(n.connection_entity_id).state)&&void 0!==c?c:0;t.state=Math.min(g,y,e)}else t.state=Math.min(g,y);i.set(_,t.prevParentState+t.state),e.set(m,t.prevChildState+t.state)}else t.state=0;t.ready=!0,(!n&&"remaining_parent_state"===m.type&&((null===(l=m.add_entities)||void 0===l?void 0:l.length)||(null===(d=m.subtract_entities)||void 0===d?void 0:d.length))&&y===1/0||"remaining_child_state"===_.type&&((null===(h=_.add_entities)||void 0===h?void 0:h.length)||(null===(u=_.subtract_entities)||void 0===u?void 0:u.length))&&g===1/0)&&(i.set(_,t.prevParentState),e.set(m,t.prevChildState),this._calcConnection(t,e,i,!0))}_getMemoizedState(t){if(!this.entityStates.has(t)){const e="string"==typeof t?{entity_id:t,children:[]}:t,i=this._getEntityState(e),n=this._getUnitOfMeasurement(e.unit_of_measurement||i.attributes.unit_of_measurement),s=Object.assign(Object.assign({},ve(this.config.unit_prefix,Number(i.state),n)),{last_updated:i.last_updated});if("passthrough"===e.type&&(s.state=this.connections.filter((t=>t.passthroughs.includes(e))).reduce(((t,e)=>e.ready?t+e.state:1/0),0)),e.add_entities&&e.add_entities.forEach((t=>{const e=this._getEntityState({entity_id:t,children:[]}),{state:i}=ve(this.config.unit_prefix,Number(e.state),this._getUnitOfMeasurement(e.attributes.unit_of_measurement||n));s.state+=i})),e.subtract_entities&&e.subtract_entities.forEach((t=>{const e=this._getEntityState({entity_id:t,children:[]}),{state:i}=ve(this.config.unit_prefix,Number(e.state),this._getUnitOfMeasurement(e.attributes.unit_of_measurement||n));s.state-=Math.min(i,s.state)})),s.state===1/0)return s;this.entityStates.set(t,s)}const e=this.entityStates.get(t);return this.reconciledStates.has(t)?Object.assign(Object.assign({},e),{state:this.reconciledStates.get(t)}):e}_reconcileConnections(){let t=!1;this.config.sections.forEach((e=>{e.entities.forEach((e=>{var i,n;if(e.parents_sum){const n=si(e,"parents",null!==(i=this.connectionsByChild.get(e))&&void 0!==i?i:[],(t=>this._getMemoizedState(t)));n.size&&(t=!0,n.forEach(((t,e)=>{this.reconciledStates.set(e,t)})))}if(e.children_sum){const i=si(e,"children",null!==(n=this.connectionsByParent.get(e))&&void 0!==n?n:[],(t=>this._getMemoizedState(t)));i.size&&(t=!0,i.forEach(((t,e)=>{this.reconciledStates.set(e,t)})))}}))})),t&&(this.entityStates.clear(),this._calcConnections())}_calcBoxes(){this.statePerPixel=0,this.config.static_scale&&this._calcBoxHeights([{state:this.config.static_scale,size:0}],this.config.height,this.config.static_scale);const t=function(t,e){if(!e)return t;let i=[];const n=t.sections.map((t=>{const n=t.entities.filter((t=>t===e||i.includes(t.entity_id)));return i=n.flatMap((t=>t.children.map(be))),Object.assign(Object.assign({},t),{entities:n})})).filter((t=>t.entities.length>0));return Object.assign(Object.assign({},t),{sections:n})}(this.config,this.zoomEntity),e=[],i=this.vertical?this.width-32:this.config.height;t.sections.forEach((t=>{var n;let s=0;const o=t.entities.filter((t=>{const{min_state:e}=this.config,{state:i}=this._getMemoizedState(t);return i&&i>=e})).map((t=>{var e,i,n;const{state:o,unit_of_measurement:r}=this._getMemoizedState(t);s+=o;let a=t.color||"var(--primary-color)";if("random"===t.color){const e=be(t);this.randomColors.has(e)||this.randomColors.set(e,`rgb(${Math.floor(256*Math.random())}, ${Math.floor(256*Math.random())}, ${Math.floor(256*Math.random())})`),a=this.randomColors.get(e)}else if(t.color_on_state){let s=o;if("passthrough"===t.type){s=this._getMemoizedState(this._findRelatedRealEntity(t,"children")).state}const r=null!==(e=t.color_limit)&&void 0!==e?e:1,c=null!==(i=t.color_below)&&void 0!==i?i:"var(--primary-color)",l=null!==(n=t.color_above)&&void 0!==n?n:"var(--state-icon-color)";s>r?a=l:s{let e=0,n=t.boxes;t.statePerPixel!==this.statePerPixel?n=n.map((t=>{const i=Math.max(this.config.min_box_size,Math.floor(t.state/this.statePerPixel));return e+=i,Object.assign(Object.assign({},t),{size:i})})):e=n.reduce(((t,e)=>t+e.size),0);const s=i-e,o=n.length>1?s/(n.length-1):s/2;let r=n.length>1?0:s/2;return n=n.map((t=>{const e=r;return r+=t.size+o,Object.assign(Object.assign({},t),{top:e})})),Object.assign(Object.assign({},t),{boxes:n,spacerSize:o})}))}_calcBoxHeights(t,e,i){const n=i/e;n>this.statePerPixel&&(this.statePerPixel=n);let s=0;const o=t.map((t=>{if(t.size===this.config.min_box_size)return t;let e=Math.floor(t.state/this.statePerPixel);return e0?this._calcBoxHeights(o,e-s,i):{boxes:o,statePerPixel:this.statePerPixel}}highlightPath(t,e){this.highlightedEntities.push(t),e&&"children"!==e||this.connections.forEach((e=>{(e.passthroughs.includes(t)||e.parent===t)&&(e.highlighted||(e.passthroughs.forEach((t=>this.highlightedEntities.push(t))),e.highlighted=!0),this.highlightedEntities.includes(e.child)||(this.highlightedEntities.push(e.child),this.highlightPath(e.child,"children")))})),e&&"parents"!==e||this.connections.forEach((e=>{(e.passthroughs.includes(t)||e.child===t)&&(e.highlighted||(e.passthroughs.forEach((t=>this.highlightedEntities.push(t))),e.highlighted=!0),this.highlightedEntities.includes(e.parent)||(this.highlightedEntities.push(e.parent),this.highlightPath(e.parent,"parents")))}))}_handleBoxTap(t){ei(this,this.hass,t.config,"tap")}_handleBoxDoubleTap(t){ei(this,this.hass,t.config,"double_tap")}_handleMouseEnter(t){this.highlightPath(t.config),this.highlightedEntities=[...this.highlightedEntities]}_handleMouseLeave(){this.highlightedEntities=[],this.connections.forEach((t=>{t.highlighted=!1}))}_getUnitOfMeasurement(t){return"monetary"==this.config.convert_units_to?"":this.config.convert_units_to&&!t.endsWith(this.config.convert_units_to)?this.config.convert_units_to:t}_getEntityState(t){if("remaining_parent_state"===t.type){const e=this.connectionsByChild.get(t);if(!e)throw new Error("Invalid entity config "+JSON.stringify(t));const i=e.reduce(((t,e)=>e.ready?t+e.state:1/0),0),n=this._getEntityState(this._findRelatedRealEntity(t,"parents")),{unit_of_measurement:s}=ve(this.config.unit_prefix,0,this._getUnitOfMeasurement(n.attributes.unit_of_measurement));return Object.assign(Object.assign({},n),{state:i,attributes:Object.assign(Object.assign({},n.attributes),{unit_of_measurement:s})})}if("remaining_child_state"===t.type){const e=this.connectionsByParent.get(t);if(!e){if(t.children.length)throw new Error("Invalid entity config "+JSON.stringify(t));return{state:0,attributes:{}}}const i=e.reduce(((t,e)=>e.ready?t+e.state:1/0),0),n=this._getEntityState(this._findRelatedRealEntity(t,"children")),{unit_of_measurement:s}=ve(this.config.unit_prefix,0,this._getUnitOfMeasurement(n.attributes.unit_of_measurement));return Object.assign(Object.assign({},n),{state:i,attributes:Object.assign(Object.assign({},n.attributes),{unit_of_measurement:s})})}if("passthrough"===t.type){const e=this.connections.find((e=>e.passthroughs.includes(t)));if(!e)throw new Error("Invalid entity config "+JSON.stringify(t));return this._getEntityState(e.child)}let e=this.states[be(t)];if(!e){if(this.config.ignore_missing_entities)return{state:0,attributes:{unit_of_measurement:t.unit_of_measurement||"",friendly_name:t.name||be(t)}};throw new Error('Entity not found "'+be(t)+'"')}return t.attribute&&(e=Object.assign(Object.assign({},e),{state:e.attributes[t.attribute]}),t.unit_of_measurement&&(e=Object.assign(Object.assign({},e),{attributes:Object.assign(Object.assign({},e.attributes),{unit_of_measurement:t.unit_of_measurement})}))),e}_findRelatedRealEntity(t,e){let i;if("passthrough"===t.type)i=this.connections.find((e=>e.passthroughs.includes(t)));else{const n="parents"===e?this.connectionsByChild.get(t):this.connectionsByParent.get(t);if(!n)throw new Error("Invalid entity config "+JSON.stringify(t));i=n[0]}return i?"parents"===e?i.parent:i.child:t}static get styles(){return Xe}render(){try{if(this.error)throw this.error;this.entityStates.clear(),this.reconciledStates.clear();const t=Ne({container:!0,wide:!!this.config.wide,"with-header":!!this.config.title,vertical:this.vertical}),e=this.vertical?"auto":this.config.height+"px";return Object.keys(this.states).length?(this._calcConnections(),this._reconcileConnections(),this._calcBoxes(),this.lastUpdate=Date.now(),R`
${this.sections.map(((t,e)=>ni({locale:this.hass.locale,config:this.config,section:t,nextSection:this.sections[e+1],sectionIndex:e,highlightedEntities:this.highlightedEntities,connectionsByParent:this.connectionsByParent,connectionsByChild:this.connectionsByChild,allConnections:this.connections,onTap:this._handleBoxTap.bind(this),onDoubleTap:this._handleBoxDoubleTap.bind(this),onMouseEnter:this._handleMouseEnter.bind(this),onMouseLeave:this._handleMouseLeave.bind(this),vertical:this.vertical})))}
`):R`
${Pt("common.loading")}
`}catch(t){return console.error(t),R`${Qe(Se(String(t),this.config,this.hass))}`}}};t([mt({attribute:!1})],oi.prototype,"hass",void 0),t([mt({attribute:!1})],oi.prototype,"states",void 0),t([mt({attribute:!1})],oi.prototype,"forceUpdateTs",void 0),t([pt()],oi.prototype,"config",void 0),t([pt()],oi.prototype,"sections",void 0),t([pt()],oi.prototype,"entityIds",void 0),t([pt()],oi.prototype,"connections",void 0),t([pt()],oi.prototype,"connectionsByParent",void 0),t([pt()],oi.prototype,"connectionsByChild",void 0),t([pt()],oi.prototype,"reconciledStates",void 0),t([pt()],oi.prototype,"statePerPixel",void 0),t([pt()],oi.prototype,"entityStates",void 0),t([pt()],oi.prototype,"highlightedEntities",void 0),t([pt()],oi.prototype,"lastUpdate",void 0),t([pt()],oi.prototype,"vertical",void 0),t([pt()],oi.prototype,"width",void 0),t([pt()],oi.prototype,"zoomEntity",void 0),t([pt()],oi.prototype,"error",void 0),oi=t([ht("sankey-chart-base")],oi);let ri=class extends lt{shouldUpdate(t){return!(!this.config||!this.hass)&&t.has("config")}firstUpdated(){this.yamlEditor.setValue(this.config)}render(){return R``}};t([mt({attribute:!1})],ri.prototype,"config",void 0),t([function(t,e){return(({finisher:t,descriptor:e})=>(i,n)=>{var s;if(void 0===n){const n=null!==(s=i.originalKey)&&void 0!==s?s:i.key,o=null!=e?{kind:"method",placement:"prototype",key:n,descriptor:e(i.key)}:{...i,key:n};return null!=t&&(o.finisher=function(e){t(e,n)}),o}{const s=i.constructor;void 0!==e&&Object.defineProperty(i,n,e(n)),null==t||t(s,n)}})({descriptor:i=>{const n={get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof i?Symbol():"__"+i;n.get=function(){var i,n;return void 0===this[e]&&(this[e]=null!==(n=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(t))&&void 0!==n?n:null),this[e]}}return n}})}("ha-yaml-editor")],ri.prototype,"yamlEditor",void 0),ri=t([ht("sankey-chart-print-config")],ri);const ai=["grid","solar","battery"],ci=(t,e="_energy")=>t.connection[e]?t.connection[e]:null,li=(t,e,i,n,s,o="hour")=>t.callWS({type:"energy/fossil_energy_consumption",start_time:e.toISOString(),end_time:null==s?void 0:s.toISOString(),energy_statistic_ids:i,co2_statistic_id:n,period:o}),di=t=>{let e=null;if(!t)return null;for(const i of t)null!==i.change&&void 0!==i.change&&(null===e?e=i.change:e+=i.change);return e};async function hi(t,{start:e,end:i},n,s){const o=ye(i||new Date,e),r=o>35?"month":o>2?"day":"hour";let a=[];const c={};if("gCO2"==s.convert_units_to||"gCO2eq"==s.convert_units_to)for(const o of n)"Wh"==t.states[o].attributes.unit_of_measurement||"kWh"==t.states[o].attributes.unit_of_measurement||"MWh"==t.states[o].attributes.unit_of_measurement?c[o]=li(t,e,[o],s.co2_intensity_entity,i,r):a.push(o);else a=n;let l={};a.length>0&&(l=await((t,e,i,n,s="hour",o)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:null==i?void 0:i.toISOString(),statistic_ids:n,period:s,types:o}))(t,e,i,a,r,["change"]));const d={};for(const t in c){const e=100;d[t]=(h=await c[t],Object.values(h).reduce(((t,e)=>t+e),0)*e)}var h;for(const e of a)if(d[e]=di(l[e]),s.convert_units_to&&d[e]){let i=1;if("gCO2"==s.convert_units_to||"gCO2eq"==s.convert_units_to)switch(t.states[e].attributes.unit_of_measurement){case"gCO2":case"gCO2eq":i=1;break;case"ft³":case"ft3":i=s.gas_co2_intensity;break;case"CCF":case"ccf":i=100*s.gas_co2_intensity;break;case"m³":case"m3":i=s.gas_co2_intensity*ee;break;default:console.warn("Can't convert from",t.states[e].attributes.unit_of_measurement,"to",s.convert_units_to)}else if("MJ"==s.convert_units_to)switch(t.states[e].attributes.unit_of_measurement){case"MJ":i=1;break;case"MWh":i=3600;break;case"kWh":i=3.6;break;case"Wh":i=.0036;break;case"ft³":case"ft3":i=1.0551;break;case"m³":case"m3":i=37.255581;break;default:console.warn("Can't convert from",t.states[e].attributes.unit_of_measurement,"to",s.convert_units_to)}else if("monetary"==s.convert_units_to)switch(t.states[e].attributes.unit_of_measurement){case"MWh":i=s.electricity_price?1e3*s.electricity_price:0;break;case"kWh":i=s.electricity_price?s.electricity_price:0;break;case"Wh":i=s.electricity_price?.001*s.electricity_price:0;break;case"ft³":case"ft3":case"CCF":case"ccf":case"m³":case"m3":i=s.gas_price?s.gas_price:0;break;default:"monetary"==t.states[e].attributes.device_class?i=1:console.warn("Can't convert from",t.states[e].attributes.unit_of_measurement,"to",s.convert_units_to)}else console.warn("Can't convert to",s.convert_units_to);d[e]*=i}return d}function ui(t){return"solar"===t?"var(--warning-color)":"battery"===t?"var(--success-color)":void 0}const _i=(t,e)=>t.callWS({type:"config/entity_registry/get",entity_id:e});let mi=[];const pi=async t=>mi.length?Promise.resolve(mi):mi=await t.callWS({type:"config/device_registry/list"});async function gi(t,e){try{const i=await _i(t,e);if(i.area_id)return i.area_id;const n=(await pi(t)).find((t=>t.id===i.device_id));if(n&&n.area_id)return n.area_id}catch(t){console.error(t)}return null}const fi=(t,e,i)=>{const n=new Map;for(let s=e;s<=i;s++)n.set(t[s],s);return n},yi=Oe(class extends ze{constructor(t){if(super(t),t.type!==Ae)throw Error("repeat() can only be used in text expressions")}ct(t,e,i){let n;void 0===i?i=e:void 0!==e&&(n=e);const s=[],o=[];let r=0;for(const e of t)s[r]=n?n(e,r):r,o[r]=i(e,r),r++;return{values:o,keys:s}}render(t,e,i){return this.ct(t,e,i).values}update(t,[e,i,n]){var s;const o=(t=>t._$AH)(t),{values:r,keys:a}=this.ct(e,i,n);if(!Array.isArray(o))return this.ut=a,r;const c=null!==(s=this.ut)&&void 0!==s?s:this.ut=[],l=[];let d,h,u=0,_=o.length-1,m=0,p=r.length-1;for(;u<=_&&m<=p;)if(null===o[u])u++;else if(null===o[_])_--;else if(c[u]===a[m])l[m]=Ie(o[u],r[m]),u++,m++;else if(c[_]===a[p])l[p]=Ie(o[_],r[p]),_--,p--;else if(c[u]===a[p])l[p]=Ie(o[u],r[p]),De(t,l[p+1],o[u]),u++,p--;else if(c[_]===a[m])l[m]=Ie(o[_],r[m]),De(t,o[u],o[_]),_--,m++;else if(void 0===d&&(d=fi(a,m,p),h=fi(c,u,_)),d.has(c[u]))if(d.has(c[_])){const e=h.get(a[m]),i=void 0!==e?o[e]:null;if(null===i){const e=De(t,o[u]);Ie(e,r[m]),l[m]=e}else l[m]=Ie(i,r[m]),De(t,o[u],i),o[e]=null;m++}else Be(o[_]),_--;else Be(o[u]),u++;for(;m<=p;){const e=De(t,l[p+1]);Ie(e,r[m]),l[m++]=e}for(;u<=_;){const t=o[u++];null!==t&&Be(t)}return this.ut=a,((t,e=He)=>{t._$AH=e})(t,l),V}});let vi=class extends lt{constructor(){super(...arguments),this._computeSchema=()=>[{name:"min_width",selector:{text:{}}},{type:"grid",name:"",schema:[{name:"sort_by",selector:{select:{mode:"dropdown",options:[{value:"none",label:Pt("editor.sort_by.none")},{value:"state",label:Pt("editor.sort_by.state")}]}}},{name:"sort_dir",selector:{select:{mode:"dropdown",options:[{value:""},{value:"desc",label:Pt("editor.sort_dir.desc")},{value:"asc",label:Pt("editor.sort_dir.asc")}]}}},{name:"sort_group_by_parent",selector:{boolean:{}}}]}],this._computeLabel=t=>Pt("editor.fields.section."+t.name)}_valueChanged(t){const{value:e}=t.detail;this.onChange(Object.assign(Object.assign({},e),{sort_by:e.sort_by||void 0,sort_dir:e.sort_dir||void 0}))}render(){return R`

${yi(this.section.entities,(t=>this.index+be(t)),((t,e)=>R`
`))}
`}static get styles(){return a`.section{margin-bottom:16px;padding:0 10px 10px}.add-entity{display:block;margin-left:31px;margin-right:36px;margin-inline-start:31px;margin-inline-end:36px;direction:var(--direction)}.entity{display:flex;align-items:center;margin-bottom:8px}.entity .handle{visibility:hidden;padding-right:8px;cursor:move;padding-inline-end:8px;padding-inline-start:initial;direction:var(--direction)}.entity .handle>*{pointer-events:none}.entity ha-entity-picker{flex-grow:1}.edit-icon{--mdc-icon-button-size:36px}`}};t([mt({attribute:!1})],vi.prototype,"hass",void 0),t([mt({attribute:!1})],vi.prototype,"section",void 0),t([mt({attribute:!1})],vi.prototype,"index",void 0),t([mt({attribute:!1})],vi.prototype,"onChange",void 0),t([mt({attribute:!1})],vi.prototype,"onConfigEntity",void 0),t([mt({attribute:!1})],vi.prototype,"onChangeEntity",void 0),t([mt({attribute:!1})],vi.prototype,"onAddEntity",void 0),vi=t([ht("sankey-chart-section-editor")],vi);let bi=class extends lt{constructor(){super(...arguments),this._computeLabel=t=>Pt("editor.fields."+t.name)}_valueChanged(t){this.onChange(t.detail.value)}_editChild(t){var e;const{detail:{value:i},target:n}=t,s="string"==typeof this.entity?{entity_id:this.entity}:this.entity;let o=null!==(e=s.children)&&void 0!==e?e:[];"number"==typeof(null==n?void 0:n.index)?i?o[n.index]=i:o=o.filter(((t,e)=>e!==n.index)):i&&(o=[...o,i],n.value=""),this.onChange(Object.assign(Object.assign({},s),{children:o}))}_getEntityIcon(t){const e=this.hass.states[t];return e?Gt(e):void 0}render(){const t="string"==typeof this.entity?{entity_id:this.entity}:this.entity,e=Object.assign(Object.assign({},te),t),i=((t,e)=>[{name:"type",selector:{select:{mode:"dropdown",options:[{value:"entity",label:Pt("editor.entity_types.entity")},{value:"remaining_parent_state",label:Pt("editor.entity_types.remaining_parent_state")},{value:"remaining_child_state",label:Pt("editor.entity_types.remaining_child_state")},{value:"passthrough",label:Pt("editor.entity_types.passthrough")}]}}},{name:"entity_id",selector:{entity:{}}},{type:"grid",name:"",schema:[{name:"attribute",selector:{attribute:{entity_id:t.entity_id}}},{name:"unit_of_measurement",selector:{text:{}}}]},{name:"name",selector:{text:{}}},{type:"grid",name:"",schema:[{name:"icon",selector:{icon:{placeholder:e}}},{name:"color",selector:{text:{}}}]},{name:"tap_action",selector:{"ui-action":{}}},{name:"color_on_state",selector:{boolean:{}}},...t.color_on_state?[{name:"color_limit",selector:{number:{mode:"box",unit_of_measurement:t.unit_of_measurement,min:0,step:"any"}}},{name:"color_above",selector:{text:{}}},{name:"color_below",selector:{text:{}}}]:[]])(e,e.icon||this._getEntityIcon(t.entity_id));return R`

${Pt("editor.entity_editor")}

${yi(e.children||[],(t=>t),((t,e)=>R`
`))}
`}static get styles(){return a`.header{display:flex;align-items:center}.header ha-icon{display:flex}.children{margin-top:10px;padding:0 10px 10px}.child{margin-bottom:8px}`}};t([mt({attribute:!1})],bi.prototype,"hass",void 0),t([mt({attribute:!1})],bi.prototype,"entity",void 0),t([mt({attribute:!1})],bi.prototype,"onClose",void 0),t([mt({attribute:!1})],bi.prototype,"onChange",void 0),bi=t([ht("sankey-chart-entity-editor")],bi);let $i=class extends lt{constructor(){super(...arguments),this._initialized=!1,this._handleEntityChange=t=>{var e,i;this._editEntity({detail:{value:t},target:{section:null===(e=this._entityConfig)||void 0===e?void 0:e.sectionIndex,index:null===(i=this._entityConfig)||void 0===i?void 0:i.entityIndex}}),this._entityConfig=Object.assign(Object.assign({},this._entityConfig),{entity:t})},this._handleSectionChange=(t,e)=>{var i,n;this._config=Object.assign(Object.assign({},this._config),{sections:null===(n=null===(i=this._config)||void 0===i?void 0:i.sections)||void 0===n?void 0:n.map(((i,n)=>n===t?e:i))}),this._updateConfig()},this._computeLabel=t=>Pt("editor.fields."+t.name)}setConfig(t){this._config=t,this.loadCardHelpers()}shouldUpdate(){return this._initialized||this._initialize(),!0}_initialize(){var t,e;void 0!==this.hass&&void 0!==this._config&&void 0!==this._helpers&&(this._initialized=!0,customElements.get("ha-form")||null===(t=customElements.get("hui-button-card"))||void 0===t||t.getConfigElement(),customElements.get("ha-entity-picker")||null===(e=customElements.get("hui-entities-card"))||void 0===e||e.getConfigElement())}async loadCardHelpers(){this._helpers=await window.loadCardHelpers()}_valueChanged(t){if(!this._config||!this.hass)return;const e=t.target;if(e.configValue)if("function"==typeof e.configValue)this._config=e.configValue(this._config,void 0!==e.checked?e.checked:e.value);else if(""===e.value){const t=Object.assign({},this._config);delete t[e.configValue],this._config=t}else this._config=Object.assign(Object.assign({},this._config),{[e.configValue]:void 0!==e.checked?e.checked:e.value});else t.detail.value.time_period_from&&!this._config.time_period_from?t.detail.value.energy_date_selection=!1:t.detail.value.energy_date_selection&&!this._config.energy_date_selection&&(t.detail.value.time_period_from=void 0,t.detail.value.time_period_to=void 0),this._config=Object.assign({},t.detail.value);this._updateConfig()}_addEntity(t){var e;const i=t.detail.value;if(""===i)return;const n=t.target;if("number"==typeof n.section){const t=(null===(e=this._config)||void 0===e?void 0:e.sections)||[];this._config=Object.assign(Object.assign({},this._config),{sections:t.map(((t,e)=>e===n.section?Object.assign(Object.assign({},t),{entities:[...t.entities,i]}):t))})}t.target.value="",this._updateConfig()}_editEntity(t){var e;const{value:i}=t.detail,n="string"==typeof i?{entity_id:i}:i,s=t.target;if("number"==typeof s.section&&"number"==typeof s.index){const t=(null===(e=this._config)||void 0===e?void 0:e.sections)||[];this._config=Object.assign(Object.assign({},this._config),{sections:t.map(((t,e)=>{if(e!==s.section)return t;const i=t.entities[s.index],o="string"==typeof i?n:Object.assign(Object.assign({},i),n);return Object.assign(Object.assign({},t),{entities:(null==n?void 0:n.entity_id)?[...t.entities.slice(0,s.index),o,...t.entities.slice(s.index+1)]:t.entities.filter(((t,e)=>e!==s.index))})}))})}this._updateConfig()}_configEntity(t,e){var i;const n=(null===(i=this._config)||void 0===i?void 0:i.sections)||[];this._entityConfig={sectionIndex:t,entityIndex:e,entity:n[t].entities[e]}}_updateConfig(){Rt(this,"config-changed",{config:this._config})}_computeSchema(){return[{name:"title",selector:{text:{}}},{name:"energy_date_selection",selector:{boolean:{}}},{type:"grid",name:"",schema:[{name:"time_period_from",selector:{text:{}}},{name:"time_period_to",selector:{text:{}}},{name:"show_names",selector:{boolean:{}}},{name:"show_icons",selector:{boolean:{}}},{name:"show_states",selector:{boolean:{}}},{name:"show_units",selector:{boolean:{}}},{name:"layout",selector:{select:{mode:"dropdown",options:[{value:"auto",label:Pt("editor.layout.auto")},{value:"horizontal",label:Pt("editor.layout.horizontal")},{value:"vertical",label:Pt("editor.layout.vertical")}]}}},{name:"wide",selector:{boolean:{}}},{name:"height",selector:{number:{mode:"box",unit_of_measurement:"px"}}},{name:"min_box_size",selector:{number:{mode:"box",unit_of_measurement:"px"}}},{name:"min_box_distance",selector:{number:{mode:"box",unit_of_measurement:"px"}}}]},{type:"grid",name:"",schema:[{name:"min_state",selector:{number:{mode:"box",min:0,step:"any"}}},{name:"static_scale",selector:{number:{mode:"box"}}},{name:"round",selector:{number:{mode:"box",unit_of_measurement:Pt("editor.decimals")}}},{name:"unit_prefix",selector:{select:{mode:"dropdown",options:[{value:""},{value:"auto",label:Pt("editor.layout.auto")},...Object.keys(Kt).map((t=>({value:t,label:t})))]}}},{name:"sort_by",selector:{select:{mode:"dropdown",options:[{value:"none",label:Pt("editor.sort_by.none")},{value:"state",label:Pt("editor.sort_by.state")}]}}},{name:"sort_dir",selector:{select:{mode:"dropdown",options:[{value:""},{value:"desc",label:Pt("editor.sort_dir.desc")},{value:"asc",label:Pt("editor.sort_dir.asc")}]}}},{name:"throttle",selector:{number:{mode:"box",unit_of_measurement:"ms"}}}]}]}render(){if(!this.hass||!this._helpers)return R``;const t="km"==this.hass.config.unit_system.length,e=$e(this._config||{},t),{autoconfig:i}=e,n=e.sections||[];return this._entityConfig?R``:R`
${i?R``:F}
${i?F:this._renderSections(n)}

${Pt("editor.yaml_disclaimer")}

${Pt("editor.docs")}

`}_renderSections(t){return R`

${Pt("editor.sections")}

${yi(t,((t,e)=>e),((t,e)=>R``))}${Pt("editor.add_section")}
`}static get styles(){return a`.card-config{padding:16px}.options{display:grid;margin-bottom:20px}.autoconfig{display:flex;justify-content:space-between;margin-bottom:16px}.sections{display:flex;flex-direction:column;margin-bottom:20px}ha-formfield{padding-bottom:8px}`}};t([mt({attribute:!1})],$i.prototype,"hass",void 0),t([mt({attribute:!1})],$i.prototype,"lovelace",void 0),t([pt()],$i.prototype,"_config",void 0),t([pt()],$i.prototype,"_helpers",void 0),t([pt()],$i.prototype,"_entityConfig",void 0),$i=t([ht("sankey-chart-editor")],$i),console.info(`%c sankey-chart %c ${Pt("common.version")} 3.10.1 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"sankey-chart",name:"Sankey Chart",description:"A card to display a sankey chart. For example for power or energy consumption",documentationURL:"https://github.com/MindFreeze/ha-sankey-chart"});let wi=class extends(Ee(lt)){constructor(){super(...arguments),this.states={},this.entityIds=[]}static async getConfigElement(){return document.createElement("sankey-chart-editor")}static getStubConfig(){return{autoconfig:{print_yaml:!1,group_by_floor:!0,group_by_area:!0}}}hassSubscribe(){const t=this.config.autoconfig||"object"==typeof this.config.autoconfig;if(this.config.energy_date_selection){const e=Date.now(),i=(t,n)=>{const s=ci(this.hass);s?t(s):Date.now()-e>1e4?(console.debug(ci(this.hass)),n(new Error("No energy data received. Make sure to add a `type: energy-date-selection` card to this screen."))):setTimeout((()=>i(t,n)),100)},n=new Promise(i);return setTimeout((()=>{this.error||Object.keys(this.states).length||(this.error=new Error("Something went wrong. No energy data received."),console.debug(ci(this.hass)))}),2e4),n.catch((t=>{this.error=t})),[n.then((async e=>{if(t&&!this.config.sections.length)try{await this.autoconfig(e.prefs)}catch(t){this.error=new Error((null==t?void 0:t.message)||t)}return e.subscribe((async i=>{if(t&&!this.config.sections.length)try{await this.autoconfig(e.prefs)}catch(t){return void(this.error=new Error((null==t?void 0:t.message)||t))}if(this.entityIds.length){const t={convert_units_to:this.config.convert_units_to,co2_intensity_entity:this.config.co2_intensity_entity,gas_co2_intensity:this.config.gas_co2_intensity,electricity_price:this.config.electricity_price,gas_price:this.config.gas_price},e=await hi(this.hass,i,this.entityIds,t),n={};Object.keys(e).forEach((t=>{this.hass.states[t]&&(n[t]=Object.assign(Object.assign({},this.hass.states[t]),{state:String(e[t])}))})),this.states=n}this.forceUpdateTs=Date.now()}))}))]}if(this.config.time_period_from){const e=async()=>{if(t&&!this.config.sections.length&&await this.autoconfig(),this.config.time_period_from){try{const{start:t,end:e}=ke(this.config.time_period_from,this.config.time_period_to);if(this.entityIds.length){const i={convert_units_to:this.config.convert_units_to,co2_intensity_entity:this.config.co2_intensity_entity,gas_co2_intensity:this.config.gas_co2_intensity,electricity_price:this.config.electricity_price,gas_price:this.config.gas_price},n=await hi(this.hass,{start:t,end:e},this.entityIds,i),s={};Object.keys(n).forEach((t=>{this.hass.states[t]&&(s[t]=Object.assign(Object.assign({},this.hass.states[t]),{state:String(n[t])}))})),this.states=s}}catch(t){this.error=t}this.forceUpdateTs=Date.now()}};e();const i=setInterval(e,this.config.throttle||1e3);return[()=>clearInterval(i)]}return[]}setConfig(t,e){if("object"!=typeof t)throw new Error(Pt("common.invalid_configuration"));this.setNormalizedConfig($e(t,e)),this.resetSubscriptions()}setNormalizedConfig(t){this.config=t,this.entityIds=[],this.config.sections.forEach((({entities:t})=>{t.forEach((t=>{"entity"===t.type&&this.entityIds.push(t.entity_id),t.children.forEach((t=>{"object"==typeof t&&t.connection_entity_id&&this.entityIds.push(t.connection_entity_id)})),t.add_entities&&t.add_entities.forEach((t=>this.entityIds.push(t))),t.subtract_entities&&t.subtract_entities.forEach((t=>this.entityIds.push(t)))}))}))}async autoconfig(t){var e,i,n,s;t||(t=await(s=this.hass,s.callWS({type:"energy/get_prefs"})));const o=[];((null==t?void 0:t.energy_sources)||[]).forEach((t=>{ai.includes(t.type)&&[t,...t.flow_from||[]].forEach((e=>{e.stat_energy_from&&(this.hass.states[e.stat_energy_from]?o.push(Object.assign(Object.assign({},t),e)):console.warn("Ignoring missing entity "+e.stat_energy_from))}))})),o.sort(((t,e)=>t.type===e.type?0:"solar"===t.type||"battery"===t.type&&"solar"!==e.type?-1:1));const r=[],a={};t.device_consumption.forEach(((t,e)=>{const i={id:t.stat_consumption,name:t.name,parent:t.included_in_stat};i.parent&&(a[i.id]=i.parent),r.push(i)}));const c=r.filter((t=>!a[t.id])),l={entity_id:"total",type:o.length?"remaining_parent_state":"remaining_child_state",name:"Total Consumption",children:["unknown"],children_sum:{should_be:"equal_or_less",reconcile_to:"max"}},d=[{entities:o.map((t=>{var e;const i=t.stat_energy_to?[t.stat_energy_to]:(null===(e=t.flow_to)||void 0===e?void 0:e.map((t=>t.stat_energy_to)))||void 0;return{entity_id:t.stat_energy_from,subtract_entities:i,type:"entity",color:ui(t.type),children:["total"]}}))},{entities:[l]}].filter((t=>t.entities.length>0)),h=o.filter((t=>"grid"===t.type)),u=new Set;h.forEach((t=>{var e;(null===(e=null==t?void 0:t.flow_to)||void 0===e?void 0:e.length)&&t.flow_to.forEach((({stat_energy_to:e})=>{u.has(e)||(u.add(e),d[1].entities.unshift({entity_id:e,subtract_entities:(t.flow_from||[]).map((t=>t.stat_energy_from)),type:"entity",color:ui(t.type),children:[]}),d[0].entities.forEach((t=>{t.children.unshift(e)})))}))}));const _=o.find((t=>"battery"===t.type));_&&_.stat_energy_from&&_.stat_energy_to&&(d[1].entities.unshift({entity_id:_.stat_energy_to,subtract_entities:[_.stat_energy_from],type:"entity",color:ui(_.type),children:[]}),d[0].entities.forEach((t=>{t.children.unshift(_.stat_energy_to)})));const m=!1!==(null===(e=this.config.autoconfig)||void 0===e?void 0:e.group_by_floor),p=!1!==(null===(i=this.config.autoconfig)||void 0===i?void 0:i.group_by_area);if(m||p){const t=await async function(t,e){const i={};for(const n of e){const e=await gi(t,n),s=e?t.areas[e]:{area_id:"no_area",name:"No area"};i[s.area_id]||(i[s.area_id]={area:s,entities:[]}),i[s.area_id].entities.push(n)}return i}(this.hass,c.map((t=>t.id))),e=Object.values(t).sort(((t,e)=>"No area"===t.area.name?1:"No area"===e.area.name?-1:0)),i=await(t=>t.callWS({type:"config/floor_registry/list"}))(this.hass),n=e.filter((t=>!t.area.floor_id));m&&n.length!==e.length?(l.children=[...l.children,...i.map((t=>t.floor_id)),...p?n.map((t=>t.area.area_id)):n.map((t=>t.entities)).flat()],d.push({entities:[...i.map((t=>({entity_id:t.floor_id,type:"remaining_child_state",name:t.name,children:p?e.filter((e=>e.area.floor_id===t.floor_id)).map((t=>t.area.area_id)):e.filter((e=>e.area.floor_id===t.floor_id)).map((t=>t.entities)).flat()})))],sort_by:"state"})):l.children=[...l.children,...e.map((t=>t.area.area_id))],p&&d.push({entities:e.map((({area:t,entities:e})=>({entity_id:t.area_id,type:"remaining_child_state",name:t.name,children:e}))),sort_by:"state",sort_group_by_parent:!0})}else l.children=[...l.children,...c.map((t=>t.id))];const g=this.getDeviceSections(a,r);g.forEach(((t,e)=>{t.length&&d.push({entities:t.map((t=>{var i;return{entity_id:t.id,type:"entity",name:t.name,children:(null===(i=g[e+1])||void 0===i?void 0:i.filter((e=>e.parent===t.id)).map((t=>t.id)))||[]}})),sort_by:"state",sort_group_by_parent:!0})}));const f=d.findIndex((t=>t.entities.find((t=>"total"===t.entity_id))));-1!==f&&d[f+1]&&(null===(n=d[f+1])||void 0===n||n.entities.push({entity_id:"unknown",type:"remaining_parent_state",name:"Unknown",children:[]})),we(d),this.setNormalizedConfig(Object.assign(Object.assign({},this.config),{sections:d}))}getDeviceSections(t,e){const i=[],n=[],s=Object.values(t),o={};return e.forEach((e=>{s.includes(e.id)?(i.push(e),o[e.id]=t[e.id]):n.push(e)})),i.length>0?[...this.getDeviceSections(o,i),n]:[e]}render(){var t,e;if(this.error)return console.error(this.error),R`${Qe(Se(String(this.error),this.config,this.hass))}`;const i=null===(t=this.config.autoconfig)||void 0===t?void 0:t.print_yaml;return R`${i&&this.config.sections.length?R``:""}`}};t([mt({attribute:!1})],wi.prototype,"hass",void 0),t([pt()],wi.prototype,"config",void 0),t([pt()],wi.prototype,"states",void 0),t([pt()],wi.prototype,"entityIds",void 0),t([pt()],wi.prototype,"error",void 0),t([pt()],wi.prototype,"forceUpdateTs",void 0),wi=t([ht("sankey-chart")],wi);var xi=wi;export{xi as default};