function e(e,t,o,i){var a,n=arguments.length,r=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,o,i);else for(var l=e.length-1;l>=0;l--)(a=e[l])&&(r=(n<3?a(r):n>3?a(t,o,r):a(t,o))||r);return n>3&&r&&Object.defineProperty(t,o,r),r}"function"==typeof SuppressedError&&SuppressedError;const t=window,o=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,i=Symbol(),a=new WeakMap;class n{constructor(e,t,o){if(this._$cssResult$=!0,o!==i)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(o&&void 0===e){const o=void 0!==t&&1===t.length;o&&(e=a.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),o&&a.set(t,e))}return e}toString(){return this.cssText}}const r=(e,...t)=>{const o=1===e.length?e[0]:t.reduce(((t,o,i)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+e[i+1]),e[0]);return new n(o,e,i)},l=o?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const o of e.cssRules)t+=o.cssText;return(e=>new n("string"==typeof e?e:e+"",void 0,i))(t)})(e):e;var s;const d=window,c=d.trustedTypes,u=c?c.emptyScript:"",h=d.reactiveElementPolyfillSupport,p={toAttribute(e,t){switch(t){case Boolean:e=e?u:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let o=e;switch(t){case Boolean:o=null!==e;break;case Number:o=null===e?null:Number(e);break;case Object:case Array:try{o=JSON.parse(e)}catch(e){o=null}}return o}},v=(e,t)=>t!==e&&(t==t||e==e),_={attribute:!0,type:String,converter:p,reflect:!1,hasChanged:v},m="finalized";class f extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(e){var t;this.finalize(),(null!==(t=this.h)&&void 0!==t?t:this.h=[]).push(e)}static get observedAttributes(){this.finalize();const e=[];return this.elementProperties.forEach(((t,o)=>{const i=this._$Ep(o,t);void 0!==i&&(this._$Ev.set(i,o),e.push(i))})),e}static createProperty(e,t=_){if(t.state&&(t.attribute=!1),this.finalize(),this.elementProperties.set(e,t),!t.noAccessor&&!this.prototype.hasOwnProperty(e)){const o="symbol"==typeof e?Symbol():"__"+e,i=this.getPropertyDescriptor(e,o,t);void 0!==i&&Object.defineProperty(this.prototype,e,i)}}static getPropertyDescriptor(e,t,o){return{get(){return this[t]},set(i){const a=this[e];this[t]=i,this.requestUpdate(e,a,o)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)||_}static finalize(){if(this.hasOwnProperty(m))return!1;this[m]=!0;const e=Object.getPrototypeOf(this);if(e.finalize(),void 0!==e.h&&(this.h=[...e.h]),this.elementProperties=new Map(e.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,t=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const o of t)this.createProperty(o,e[o])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const o=new Set(e.flat(1/0).reverse());for(const e of o)t.unshift(l(e))}else void 0!==e&&t.push(l(e));return t}static _$Ep(e,t){const o=t.attribute;return!1===o?void 0:"string"==typeof o?o:"string"==typeof e?e.toLowerCase():void 0}_$Eu(){var e;this._$E_=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(e=this.constructor.h)||void 0===e||e.forEach((e=>e(this)))}addController(e){var t,o;(null!==(t=this._$ES)&&void 0!==t?t:this._$ES=[]).push(e),void 0!==this.renderRoot&&this.isConnected&&(null===(o=e.hostConnected)||void 0===o||o.call(e))}removeController(e){var t;null===(t=this._$ES)||void 0===t||t.splice(this._$ES.indexOf(e)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((e,t)=>{this.hasOwnProperty(t)&&(this._$Ei.set(t,this[t]),delete this[t])}))}createRenderRoot(){var e;const i=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,i)=>{o?e.adoptedStyleSheets=i.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):i.forEach((o=>{const i=document.createElement("style"),a=t.litNonce;void 0!==a&&i.setAttribute("nonce",a),i.textContent=o.cssText,e.appendChild(i)}))})(i,this.constructor.elementStyles),i}connectedCallback(){var e;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostConnected)||void 0===t?void 0:t.call(e)}))}enableUpdating(e){}disconnectedCallback(){var e;null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostDisconnected)||void 0===t?void 0:t.call(e)}))}attributeChangedCallback(e,t,o){this._$AK(e,o)}_$EO(e,t,o=_){var i;const a=this.constructor._$Ep(e,o);if(void 0!==a&&!0===o.reflect){const n=(void 0!==(null===(i=o.converter)||void 0===i?void 0:i.toAttribute)?o.converter:p).toAttribute(t,o.type);this._$El=e,null==n?this.removeAttribute(a):this.setAttribute(a,n),this._$El=null}}_$AK(e,t){var o;const i=this.constructor,a=i._$Ev.get(e);if(void 0!==a&&this._$El!==a){const e=i.getPropertyOptions(a),n="function"==typeof e.converter?{fromAttribute:e.converter}:void 0!==(null===(o=e.converter)||void 0===o?void 0:o.fromAttribute)?e.converter:p;this._$El=a,this[a]=n.fromAttribute(t,e.type),this._$El=null}}requestUpdate(e,t,o){let i=!0;void 0!==e&&(((o=o||this.constructor.getPropertyOptions(e)).hasChanged||v)(this[e],t)?(this._$AL.has(e)||this._$AL.set(e,t),!0===o.reflect&&this._$El!==e&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(e,o))):i=!1),!this.isUpdatePending&&i&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const e=this.scheduleUpdate();return null!=e&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var e;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((e,t)=>this[t]=e)),this._$Ei=void 0);let t=!1;const o=this._$AL;try{t=this.shouldUpdate(o),t?(this.willUpdate(o),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostUpdate)||void 0===t?void 0:t.call(e)})),this.update(o)):this._$Ek()}catch(e){throw t=!1,this._$Ek(),e}t&&this._$AE(o)}willUpdate(e){}_$AE(e){var t;null===(t=this._$ES)||void 0===t||t.forEach((e=>{var t;return null===(t=e.hostUpdated)||void 0===t?void 0:t.call(e)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(e){return!0}update(e){void 0!==this._$EC&&(this._$EC.forEach(((e,t)=>this._$EO(t,this[t],e))),this._$EC=void 0),this._$Ek()}updated(e){}firstUpdated(e){}}var y;f[m]=!0,f.elementProperties=new Map,f.elementStyles=[],f.shadowRootOptions={mode:"open"},null==h||h({ReactiveElement:f}),(null!==(s=d.reactiveElementVersions)&&void 0!==s?s:d.reactiveElementVersions=[]).push("1.6.3");const g=window,b=g.trustedTypes,w=b?b.createPolicy("lit-html",{createHTML:e=>e}):void 0,x="$lit$",k=`lit$${(Math.random()+"").slice(9)}$`,S="?"+k,$=`<${S}>`,C=document,E=()=>C.createComment(""),A=e=>null===e||"object"!=typeof e&&"function"!=typeof e,M=Array.isArray,P=e=>M(e)||"function"==typeof(null==e?void 0:e[Symbol.iterator]),z="[ \t\n\f\r]",D=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,O=/>/g,N=RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),j=/'/g,B=/"/g,L=/^(?:script|style|textarea|title)$/i,I=e=>(t,...o)=>({_$litType$:e,strings:t,values:o}),H=I(1),R=I(2),F=Symbol.for("lit-noChange"),U=Symbol.for("lit-nothing"),G=new WeakMap,V=C.createTreeWalker(C,129,null,!1);function W(e,t){if(!Array.isArray(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==w?w.createHTML(t):t}const Z=(e,t)=>{const o=e.length-1,i=[];let a,n=2===t?"":"",r=D;for(let t=0;t"===s[0]?(r=null!=a?a:D,d=-1):void 0===s[1]?d=-2:(d=r.lastIndex-s[2].length,l=s[1],r=void 0===s[3]?N:'"'===s[3]?B:j):r===B||r===j?r=N:r===T||r===O?r=D:(r=N,a=void 0);const u=r===N&&e[t+1].startsWith("/>")?" ":"";n+=r===D?o+$:d>=0?(i.push(l),o.slice(0,d)+x+o.slice(d)+k+u):o+k+(-2===d?(i.push(void 0),t):u)}return[W(e,n+(e[o]||"")+(2===t?"":"")),i]};class K{constructor({strings:e,_$litType$:t},o){let i;this.parts=[];let a=0,n=0;const r=e.length-1,l=this.parts,[s,d]=Z(e,t);if(this.el=K.createElement(s,o),V.currentNode=this.el.content,2===t){const e=this.el.content,t=e.firstChild;t.remove(),e.append(...t.childNodes)}for(;null!==(i=V.nextNode())&&l.length0){i.textContent=b?b.emptyScript:"";for(let o=0;o2||""!==o[0]||""!==o[1]?(this._$AH=Array(o.length-1).fill(new String),this.strings=o):this._$AH=U}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(e,t=this,o,i){const a=this.strings;let n=!1;if(void 0===a)e=Y(this,e,t,0),n=!A(e)||e!==this._$AH&&e!==F,n&&(this._$AH=e);else{const i=e;let r,l;for(e=a[0],r=0;r{var i,a;const n=null!==(i=null==o?void 0:o.renderBefore)&&void 0!==i?i:t;let r=n._$litPart$;if(void 0===r){const e=null!==(a=null==o?void 0:o.renderBefore)&&void 0!==a?a:null;n._$litPart$=r=new q(t.insertBefore(E(),e),e,void 0,null!=o?o:{})}return r._$AI(e),r})(t,this.renderRoot,this.renderOptions)}connectedCallback(){var e;super.connectedCallback(),null===(e=this._$Do)||void 0===e||e.setConnected(!0)}disconnectedCallback(){var e;super.disconnectedCallback(),null===(e=this._$Do)||void 0===e||e.setConnected(!1)}render(){return F}}se.finalized=!0,se._$litElement$=!0,null===(re=globalThis.litElementHydrateSupport)||void 0===re||re.call(globalThis,{LitElement:se});const de=globalThis.litElementPolyfillSupport;null==de||de({LitElement:se}),(null!==(le=globalThis.litElementVersions)&&void 0!==le?le:globalThis.litElementVersions=[]).push("3.3.3");const ce=e=>t=>"function"==typeof t?((e,t)=>(customElements.define(e,t),t))(e,t):((e,t)=>{const{kind:o,elements:i}=t;return{kind:o,elements:i,finisher(t){customElements.define(e,t)}}})(e,t),ue=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?{...t,finisher(o){o.createProperty(t.key,e)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:t.key,initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(o){o.createProperty(t.key,e)}},he=(e,t,o)=>{t.constructor.createProperty(o,e)};function pe(e){return(t,o)=>void 0!==o?he(e,t,o):ue(e,t)}function ve(e){return pe({...e,state:!0})}function _e(e,t){return(({finisher:e,descriptor:t})=>(o,i)=>{var a;if(void 0===i){const i=null!==(a=o.originalKey)&&void 0!==a?a:o.key,n=null!=t?{kind:"method",placement:"prototype",key:i,descriptor:t(o.key)}:{...o,key:i};return null!=e&&(n.finisher=function(t){e(t,i)}),n}{const a=o.constructor;void 0!==t&&Object.defineProperty(o,i,t(i)),null==e||e(a,i)}})({descriptor:o=>{const i={get(){var t,o;return null!==(o=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(e))&&void 0!==o?o:null},enumerable:!0,configurable:!0};if(t){const t="symbol"==typeof o?Symbol():"__"+o;i.get=function(){var o,i;return void 0===this[t]&&(this[t]=null!==(i=null===(o=this.renderRoot)||void 0===o?void 0:o.querySelector(e))&&void 0!==i?i:null),this[t]}}return i}})}var me;null===(me=window.HTMLSlotElement)||void 0===me||me.prototype.assignedElements;const fe=(e,t)=>Number(`${Math.round(Number(`${e}e${t}`))}e-${t}`);function ye(e){return!isNaN(parseFloat(e))&&!isNaN(Number(e))}function ge(e,t=0){return ye(e)?Number(e):t}const be=r`:host{--size-circle-entity:79.99px;--mdc-icon-size:24px;--clickable-cursor:pointer;--individual-left-bottom-color:#d0cc5b;--individual-left-top-color:#964cb5;--individual-right-top-color:#b54c9d;--individual-right-bottom-color:#5bd0cc;--non-fossil-color:var(--energy-non-fossil-color, #0f9d58);--icon-non-fossil-color:var(--non-fossil-color, #0f9d58);--icon-solar-color:var(--energy-solar-color, #ff9800);--icon-individual-bottom-color:var(--individual-left-bottom-color, #d0cc5b);--icon-individual-top-color:var(--individual-left-top-color, #964cb5);--icon-grid-color:var(--energy-grid-consumption-color, #488fc2);--icon-battery-color:var(--energy-battery-in-color, #f06292);--icon-home-color:var(--energy-grid-consumption-color, #488fc2);--text-solar-color:var(--primary-text-color);--text-non-fossil-color:var(--primary-text-color);--text-individual-bottom-color:var(--primary-text-color);--text-individual-top-color:var(--primary-text-color);--text-home-color:var(--primary-text-color);--secondary-text-individual-bottom-color:var(--primary-text-color);--secondary-text-individual-top-color:var(--primary-text-color);--text-battery-state-of-charge-color:var(--primary-text-color);--cirlce-grid-color:var(--energy-grid-consumption-color, #488fc2);--circle-battery-color:var(--energy-battery-in-color, #f06292);--battery-grid-line:var(--energy-grid-return-color, #8353d1);--secondary-text-solar-color:var(--primary-text-color);--secondary-text-grid-color:var(--primary-text-color);--secondary-text-home-color:var(--primary-text-color);--secondary-text-non-fossil-color:var(--primary-text-color);--lines-svg-not-flat-line-height:106%;--lines-svg-not-flat-line-top:-2%;--lines-svg-flat-width:calc(100% - 160px);--lines-svg-not-flat-width:calc(103% - 165px);--lines-svg-not-flat-multi-indiv-height:104%;--lines-svg-not-flat-multi-indiv-width:calc(103% - var(--size-circle-entity) * 3.7);--lines-svg-not-flat-multi-indiv-width:calc(((106% - 165px) * 0.5));--lines-svg-not-flat-multi-indiv-width:calc(((130% - 246px) * 0.5));--lines-svg-not-flat-multi-indiv-right-indiv-width:calc(((130% - 210px) * 0.5));--lines-svg-not-flat-multi-indiv-right-indiv-height:103%;--lines-svg-flat-multi-indiv-width:calc((129% - 242px) * 0.5);--lines-svg-flat-left:0;--lines-svg-not-flat-left:0;--dot-size:3.5px;--transparency:var(--transparency-unused-lines);--greyed-out--line-color:#bdbdbd;--text-grid-consumption-color:var(--energy-grid-consumption-color);--text-grid-return-color:var(--energy-grid-return-color);--text-battery-in-color:var(--energy-battery-in-color);--text-battery-out-color:var(--energy-battery-out-color)}ha-card{overflow:hidden}ha-card.full-size{height:100%}.card-content.full-size{transform:scale(2) translateY(30%)}.card-content{position:relative;margin:0 auto}.circle{width:80px;height:80px;border-radius:50%;box-sizing:border-box;border:2px solid;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;font-size:12px;line-height:12px;position:relative;text-decoration:none;color:var(--primary-text-color);gap:2px}.card-content,.row{max-width:470px}.lines{position:absolute;bottom:0;left:var(--size-circle-entity);width:100%;height:146px;display:flex;justify-content:flex-start;padding:0 16px 16px;box-sizing:border-box}.lines:not(.multi-individual) svg.flat-line{left:var(--lines-svg-flat-left)}.lines:not(.multi-individual) svg:not(.flat-line){left:var(--lines-svg-not-flat-left)}.lines:has(svg:not(.flat-line)){margin-left:-1%}.lines.individual-bottom-individual-top{bottom:110px}.lines.high{bottom:100px;height:156px}.lines svg{width:var(--lines-svg-flat-width);height:100%;max-width:340px;position:relative}.lines svg:not(.flat-line){width:var(--lines-svg-not-flat-width);height:var(--lines-svg-not-flat-line-height);top:var(--lines-svg-not-flat-line-top)}.multi-individual{left:calc(var(--size-circle-entity) + 2%);margin-left:-2.2%!important}.multi-individual svg{width:var(--lines-svg-flat-multi-indiv-width)}.multi-individual svg:not(.flat-line){width:var(--lines-svg-not-flat-multi-indiv-width);margin-top:1px;height:var(--lines-svg-not-flat-multi-indiv-height)}.row{display:flex;justify-content:space-between;max-width:500px;margin:0 auto}.circle-container{display:flex;flex-direction:column;align-items:center;z-index:2}.circle-container.solar{height:130px}.circle-container.individual-top{height:130px}.circle-container.individual-bottom{justify-content:flex-end}.circle-container.individual-bottom.bottom{position:relative;top:-20px;margin-bottom:-20px}.circle-container.battery{height:110px;justify-content:flex-end}.spacer{width:var(--size-circle-entity)}.circle-container .circle{cursor:var(--clickable-cursor)}#battery-grid{stroke:var(--battery-grid-line)}ha-icon{padding-bottom:2px}ha-icon.small{--mdc-icon-size:12px}.label{color:var(--secondary-text-color);font-size:12px;max-width:80px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;min-height:20px}line,path{stroke:var(--disabled-text-color);stroke-width:1;fill:none}path.transparency{opacity:calc(calc(100 - var(--transparency))/ 100)}path.grey{stroke:var(--greyed-out--line-color)!important}.circle svg{position:absolute;fill:none;stroke-width:4px;width:100%;height:100%;top:0;left:0}span.secondary-info{color:var(--primary-text-color);font-size:12px;max-width:60px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.individual-top circle,.individual-top path{stroke:var(--individual-left-top-color)}#individual-left-bottom-icon{color:var(--icon-individual-left-bottom-color)}#individual-left-top-icon{color:var(--icon-individual-left-top-color)}#individual-right-bottom-icon{color:var(--icon-individual-right-bottom-color)}#individual-right-top-icon{color:var(--icon-individual-right-top-color)}#solar-icon{color:var(--icon-solar-color)}circle.individual-top{stroke-width:4;width:var(--dot-size);fill:var(--individual-left-top-color)}circle.individual-bottom{stroke-width:4;width:var(--dot-size);fill:var(--individual-left-bottom-color)}.individual-top .circle{border-color:var(--individual-left-top-color)}.individual-bottom circle,.individual-bottom path{stroke:var(--individual-left-bottom-color)}.individual-bottom .circle{border-color:var(--individual-left-bottom-color)}.individual-right-top .circle{border-color:var(--individual-right-top-color)}circle.individual-right-top .circle{fill:var(--individual-right-top-color)}.individual-right-top circle,.individual-right-top path{stroke:var(--individual-right-top-color)}.individual-right-bottom .circle{border-color:var(--individual-right-bottom-color)}circle.individual-right-bottom .circle{fill:var(--individual-right-bottom-color)}.individual-right-bottom circle,.individual-right-bottom path{stroke:var(--individual-right-bottom-color)}.right-individual-flow-container{position:absolute;right:calc(var(--size-circle-entity) - 27% * 1.1 + 6px);width:100%;display:flex;justify-content:flex-end;height:156px;bottom:100px;padding:0 16px 16px;margin-right:-1.2%;box-sizing:border-box;pointer-events:none}.right-individual-flow-container>svg{width:var(--lines-svg-not-flat-multi-indiv-right-indiv-width)}.right-individual-flow{height:var(--lines-svg-not-flat-multi-indiv-right-indiv-height);margin-top:2px;width:var(--lines-svg-not-flat-multi-indiv-width);top:var(--lines-svg-not-flat-line-top);max-width:340px;position:relative}.circle-container.low-carbon{height:130px}.low-carbon path{stroke:var(--non-fossil-color)}.low-carbon .circle{border-color:var(--non-fossil-color)}.low-carbon ha-icon:not(.small){color:var(--icon-non-fossil-color)}circle.low-carbon{stroke-width:4;fill:var(--non-fossil-color);stroke:var(--non-fossil-color)}.solar{color:var(--primary-text-color)}.solar .circle{border-color:var(--energy-solar-color)}.solar ha-icon:not(.small){color:var(--icon-solar-color)}circle.solar,path.solar{stroke:var(--energy-solar-color)}circle.solar{stroke-width:4;fill:var(--energy-solar-color)}.battery .circle{border-color:var(--circle-battery-color)}circle.battery,path.battery{stroke:var(--energy-battery-out-color)}circle.battery-home,path.battery-home{stroke:var(--energy-battery-out-color)}circle.battery-home{stroke-width:4;fill:var(--energy-battery-out-color)}circle.battery-solar,path.battery-solar{stroke:var(--energy-battery-in-color)}circle.battery-solar{stroke-width:4;fill:var(--energy-battery-in-color)}.battery-in{color:var(--energy-battery-in-color)}.battery-out{color:var(--energy-battery-out-color)}span.battery-in{color:var(--text-battery-in-color)}span.battery-out{color:var(--text-battery-out-color)}path.battery-from-grid{stroke:var(--energy-grid-consumption-color)}path.battery-to-grid{stroke:var(--battery-grid-line)}.battery ha-icon:not(.small){color:var(--icon-battery-color)}circle.battery-to-grid,circle.return,path.return{stroke:var(--energy-grid-return-color)}circle.battery-to-grid,circle.return{stroke-width:4;fill:var(--energy-grid-return-color)}.return{color:var(--energy-grid-return-color)}span.return{color:var(--text-grid-return-color)}.grid .circle{border-color:var(--circle-grid-color)}.consumption{color:var(--energy-grid-consumption-color)}span.consumption{color:var(--text-grid-consumption-color)}circle.battery-from-grid,circle.grid,path.grid{stroke:var(--energy-grid-consumption-color)}circle.battery-from-grid,circle.grid{stroke-width:4;fill:var(--energy-grid-consumption-color)}.grid ha-icon:not(.small){color:var(--icon-grid-color)}.home .circle{border-width:0;border-color:var(--primary-color)}.home .circle.border{border-width:2px}.home ha-icon:not(.small){color:var(--icon-home-color)}.circle svg circle{animation:rotate-in .6s ease-in;transition:stroke-dashoffset .4s,stroke-dasharray .4s;fill:none}span.solar{color:var(--text-solar-color)}span.low-carbon{color:var(--text-non-fossil-color)}span.low-carbon.secondary-info{color:var(--secondary-text-non-fossil-color)}#home-circle{color:var(--text-home-color);z-index:2}.individual-bottom .circle{color:var(--text-individual-bottom-color)}.individual-top .circle{color:var(--text-individual-top-color)}.individual-bottom span.secondary-info{color:var(--secondary-text-individual-bottom-color)}.individual-top span.secondary-info{color:var(--secondary-text-individual-top-color)}span.secondary-info.left-top{color:var(--secondary-text-individual-left-top-color)}span.individual-left-top{color:var(--text-individual-left-top-color)}span.secondary-info.left-bottom{color:var(--secondary-text-individual-left-bottom-color)}span.individual-left-bottom{color:var(--text-individual-left-bottom-color)}span.secondary-info.right-top{color:var(--secondary-text-individual-right-top-color)}span.individual-right-top{color:var(--text-individual-right-top-color)}span.secondary-info.right-bottom{color:var(--secondary-text-individual-right-bottom-color)}span.individual-right-bottom{color:var(--text-individual-right-bottom-color)}.solar span.secondary-info{color:var(--secondary-text-solar-color)}.grid span.secondary-info{color:var(--secondary-text-grid-color)}.home span.secondary-info{color:var(--secondary-text-home-color)}#battery-state-of-charge-text{color:var(--text-battery-state-of-charge-color)}@keyframes rotate-in{from{stroke-dashoffset:238.76104;stroke-dasharray:238.76104}}.card-actions{display:flex;justify-content:space-between;align-items:center}.card-actions a{text-decoration:none}.home-circle-sections{pointer-events:none}`,we={maxFlowRate:6,minFlowRate:.75,wattDecimals:0,kilowattDecimals:1,minExpectedPower:.01,maxExpectedPower:2e3,wattThreshold:1e3,transparencyZeroLines:0,displayZeroLines:{mode:"show",transparency:50,grey_color:[189,189,189]}};const xe=(e,t)=>{var o;return ye(null===(o=e.states[t])||void 0===o?void 0:o.state)};var ke,Se;function $e(){return($e=Object.assign||function(e){for(var t=1;t-1?e.split(".")[1].length:0;o.minimumFractionDigits=i,o.maximumFractionDigits=i}return o},Ae=function(e,t,o,i){i=i||{},o=null==o?{}:o;var a=new Event(t,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return a.detail=o,e.dispatchEvent(a),a},Me="0.2.2";console.groupCollapsed(`%c⚡ Power Flow Card Plus v${Me} is installed`,"color: #488fc2; font-weight: bold"),console.log("Readme:","https://github.com/flixlix/power-flow-card-plus"),console.groupEnd();const Pe=function(e,t,o){var i;return void 0===o&&(o=!1),function(){var a=[].slice.call(arguments),n=this,r=o&&!i;clearTimeout(i),i=setTimeout((function(){i=null,o||e.apply(n,a)}),t),r&&e.apply(n,a)}}((e=>{console.log(`%c⚡ Power Flow Card Plus v${Me} %cError: ${e}`,"color: #488fc2; font-weight: bold","color: #b33a3a; font-weight: normal")}),6e4),ze=e=>{Pe(`Entity "${null!=e?e:"Unknown"}" is not available or misconfigured`)},De=(e,t)=>t&&xe(e,t)?ge(e.states[t].state):(ze(t),null),Te=["K","M","G","T","P","E","Z","Y"],Oe=(e,t)=>{var o;const i=De(e,t);if(!t||null===i)return 0;const a=null!==(o=e.states[t].attributes.unit_of_measurement)&&void 0!==o?o:"";return Ne(i,a)},Ne=(e,t)=>{const o=t.toUpperCase().slice(0,1),i=Te.indexOf(o);return i>-1?e*Math.pow(1e3,i+1):e},je=(e,t,o)=>{var i;return null===(i=e.use_new_flow_rate_model)||void 0===i||i?((e,t)=>{const o=e.max_expected_power,i=e.min_expected_power;return((e,t,o,i,a)=>e>a?o:(e-i)*(o-t)/(a-i)+t)(t,e.max_flow_rate,e.min_flow_rate,i,o)})(e,t):((e,t,o)=>{const i=null==e?void 0:e.min_flow_rate,a=null==e?void 0:e.max_flow_rate;return a-t/(o>0?o:t)*(a-i)})(e,t,o)},Be=(e,t)=>!1!==e&&t?t:"number"==typeof e?e:1.66,Le=(e,t)=>{var o;return!!(null===(o=e.entities[t])||void 0===o?void 0:o.invert_state)},Ie=e=>Math.abs(Math.min(e,0)),He=e=>Math.max(e,0),Re=(e,t,o)=>{var i,a,n;const r=null===(n=null===(a=null===(i=t.entities)||void 0===i?void 0:i[o])||void 0===a?void 0:a.secondary_info)||void 0===n?void 0:n.entity;if("string"!=typeof r)return null;const l=e.states[r].state;return ye(l)?Number(l):l},Fe=(e,t,o)=>{var i;const a=null===(i=t.entities[o])||void 0===i?void 0:i.entity;if(void 0===a)return null;if("string"==typeof a){const i=Oe(e,a);return Le(t,o)?He(i):Ie(i)}return Oe(e,a.production)},Ue=(e,t,o)=>{var i;const a=null===(i=t.entities[o])||void 0===i?void 0:i.entity;if(void 0===a)return null;if("string"==typeof a){const i=Oe(e,a);return Le(t,o)?Ie(i):He(i)}return Oe(e,a.consumption)},Ge=(e,t)=>Ue(e,t,"grid"),Ve=(e,t)=>Re(e,t,"grid"),We=(e,t)=>{var o;const i=null===(o=t.entities.solar)||void 0===o?void 0:o.entity;if(void 0===i)return null;const a=Oe(e,i);return Le(t,"solar")?Ie(a):He(a)},Ze=(e,t)=>Re(e,t,"solar"),Ke=(e,t)=>{var o;const i=null===(o=t.entities.battery)||void 0===o?void 0:o.state_of_charge;return void 0===i?null:De(e,i)},Ye=(e,t)=>Fe(e,t,"battery"),Xe=(e,t)=>Ue(e,t,"battery"),qe=(e,t)=>{if(t&&xe(e,t))return e.states[t];ze(t)},Je=(e,t,o)=>{var i,a,n,r,l,s,d,c;return(null==t?void 0:t.icon)?t.icon:(null==t?void 0:t.use_metadata)?"string"==typeof(null==t?void 0:t.entity)?(null===(a=null===(i=qe(e,null==t?void 0:t.entity))||void 0===i?void 0:i.attributes)||void 0===a?void 0:a.icon)||o:(null===(l=null===(r=qe(e,null===(n=null==t?void 0:t.entity)||void 0===n?void 0:n.consumption))||void 0===r?void 0:r.attributes)||void 0===l?void 0:l.icon)||(null===(c=null===(d=qe(e,null===(s=null==t?void 0:t.entity)||void 0===s?void 0:s.production))||void 0===d?void 0:d.attributes)||void 0===c?void 0:c.icon)||o:o},Qe=(e,t,o)=>{var i,a,n,r,l,s,d,c;return(null==t?void 0:t.name)?t.name:(null==t?void 0:t.use_metadata)?"string"==typeof(null==t?void 0:t.entity)?(null===(a=null===(i=qe(e,t.entity))||void 0===i?void 0:i.attributes)||void 0===a?void 0:a.friendly_name)||o:(null===(l=null===(r=qe(e,null===(n=null==t?void 0:t.entity)||void 0===n?void 0:n.consumption))||void 0===r?void 0:r.attributes)||void 0===l?void 0:l.friendly_name)||(null===(c=null===(d=qe(e,null===(s=null==t?void 0:t.entity)||void 0===s?void 0:s.production))||void 0===d?void 0:d.attributes)||void 0===c?void 0:c.friendly_name)||o:o},et=(e,t)=>!!e&&e>=t,tt=(e,t)=>e?t?et(e,t)?e:0:e:0,ot=(e,t)=>{var o;const i=t.entities.fossil_fuel_percentage;t.entities.grid;const a=null==i?void 0:i.entity,n=null==i?void 0:i.display_zero,r=Ge(e,t);return void 0!==a&&(!0===n||null!==r&&1*r-(null!==(o=De(e,a))&&void 0!==o?o:0)/100>0)},it=(e,t)=>{var o;const i=t.entities.fossil_fuel_percentage;t.entities.grid;const a=null==i?void 0:i.entity,n=null==i?void 0:i.display_zero,r=Ge(e,t);return void 0!==a&&(!0===n||null!==r&&(!1!==ot(e,t)&&1*r-(null!==(o=De(e,a))&&void 0!==o?o:0)/100>0))},at=(e,t)=>Re(e,t,"fossil_fuel_percentage"),nt=(e,t)=>Re(e,t,"home"),rt=(e,t,o,{unit:i,unitWhiteSpace:a,decimals:n,accept_negative:r,watt_threshold:l=1e3})=>{if(null===o)return"0";if(!ye(o))return o.toString();const s=Number(o),d=void 0===i&&s>=l,c=null!=n?n:d?t.kw_decimals:t.w_decimals;return`${Ce((e=>r?e:Math.abs(e))(d?fe(s/1e3,null!=c?c:2):fe(s,null!=c?c:0)),e.locale)}${!1===a?"":" "}${i||(d?"kW":"W")}`},lt=e=>e?"#".concat(e.map((e=>e.toString(16).padStart(2,"0"))).join("")):"",st=(e,t,o)=>{let i="var(--primary-text-color)";return"string"==typeof e&&(i=t[e].color),!0===e&&(i=t[o].color),i},dt=["unavailable","unknown"],ct=({main:e,className:t,template:o,value:i,entityId:a,icon:n})=>i&&dt.includes(i)?H``:i||o?H`${n?H``:""} ${null!=o?o:i}`:H``,ut=(e,t,o,i,a,n)=>{var r,l;return H`${(null===(r=null==a?void 0:a.secondary)||void 0===r?void 0:r.has)||(null===(l=null==a?void 0:a.secondary)||void 0===l?void 0:l.template)?H`${ct({main:t,className:n,entityId:a.secondary.entity,icon:a.secondary.icon,value:rt(e,o,a.secondary.state,{unit:a.secondary.unit,unitWhiteSpace:a.secondary.unit_white_space,decimals:a.secondary.decimals,accept_negative:a.secondary.accept_negative,watt_threshold:o.watt_threshold}),template:i[`${n}Secondary`]})}`:""}`},ht=(e,t)=>{var o,i;if(e>0)return"";const a=null===(o=null==t?void 0:t.display_zero_lines)||void 0===o?void 0:o.mode;if("show"===a||void 0===a)return"";let n="";if("transparency"===a||"custom"===a){const e=null===(i=null==t?void 0:t.display_zero_lines)||void 0===i?void 0:i.transparency;(null==e||e)&&(n+="transparency ")}return"grey_out"!==a&&"custom"!==a||(n+="grey"),n},pt=(e,t)=>{var o;return t>0||"hide"!==(null===(o=null==e?void 0:e.display_zero_lines)||void 0===o?void 0:o.mode)},vt=e=>!0!==e.disable_dots,_t=(e,t,{nonFossil:o,entities:i,templatesObj:a,grid:n,newDur:r})=>{var l,s,d;return H`${o.hasPercentage?H`
${o.name}
${ut(e.hass,e,t,a,o,"low-carbon")} ${" "!==o.icon?H``:null} ${!1!==(null===(l=i.fossil_fuel_percentage)||void 0===l?void 0:l.display_zero_state)||(o.state.power||0)>((null===(s=i.fossil_fuel_percentage)||void 0===s?void 0:s.display_zero_tolerance)||0)?H`${((e,t,o,i)=>{var a,n,r,l,s,d,c,u,h;if(!o||!xe(e,o))return ze(o),"NaN";const p=null===(n=null===(a=t.entities.fossil_fuel_percentage)||void 0===a?void 0:a.unit_white_space)||void 0===n||n,v="percentage"===(null===(r=t.entities.fossil_fuel_percentage)||void 0===r?void 0:r.state_type)?"%":"W",_=1-(null!==(l=De(e,o))&&void 0!==l?l:0)/100;let m;m="string"==typeof(null===(s=t.entities.grid)||void 0===s?void 0:s.entity)?i:Oe(e,null===(d=t.entities.grid)||void 0===d?void 0:d.entity.consumption)||0;const f=null!==(u=null===(c=t.entities.fossil_fuel_percentage)||void 0===c?void 0:c.display_zero_tolerance)&&void 0!==u?u:0;if("W"===v){let o=m*_;return f&&o`:""}
${pt(t,o.state.power||0)?H`${vt(t)&&o.has&&o.state.power>0?R``:""}`:""}
`:H`
`}`},mt=1,ft=2,yt=e=>(...t)=>({_$litDirective$:e,values:t});class gt{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,t,o){this._$Ct=e,this._$AM=t,this._$Ci=o}_$AS(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}}const bt=yt(class extends gt{constructor(e){var t;if(super(e),e.type!==mt||"class"!==e.name||(null===(t=e.strings)||void 0===t?void 0:t.length)>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(e){return" "+Object.keys(e).filter((t=>e[t])).join(" ")+" "}update(e,[t]){var o,i;if(void 0===this.it){this.it=new Set,void 0!==e.strings&&(this.nt=new Set(e.strings.join(" ").split(/\s/).filter((e=>""!==e))));for(const e in t)t[e]&&!(null===(o=this.nt)||void 0===o?void 0:o.has(e))&&this.it.add(e);return this.render(t)}const a=e.element.classList;this.it.forEach((e=>{e in t||(a.remove(e),this.it.delete(e))}));for(const e in t){const o=!!t[e];o===this.it.has(e)||(null===(i=this.nt)||void 0===i?void 0:i.has(e))||(o?(a.add(e),this.it.add(e)):(a.remove(e),this.it.delete(e)))}return F}}),wt=(e,t)=>{var o;const i=(e=>{const t=JSON.parse(JSON.stringify(e)).filter((e=>null==e?void 0:e.has));return t})(e);return null!==(o=null==i?void 0:i[t])&&void 0!==o?o:void 0},xt=(e,t)=>{var o;if("sort_power"===(null===(o=e.individual_mode_config)||void 0===o?void 0:o.mode))return wt(t,1)},kt=(e,t)=>{var o;if("sort_power"===(null===(o=e.individual_mode_config)||void 0===o?void 0:o.mode))return wt(t,2)},St=(e,t)=>{var o;if("sort_power"===(null===(o=e.individual_mode_config)||void 0===o?void 0:o.mode))return wt(t,3)},$t=(e,t)=>!!kt(e,t)||!!St(e,t),Ct=(e,t)=>!!xt(e,t)||!!St(e,t),Et=(e,{battery:t,grid:o,individual:i,solar:a,newDur:n})=>H`${((e,{battery:t,grid:o,individual:i,solar:a,newDur:n})=>a.has&&pt(e,a.state.toHome||0)?H`
null==e?void 0:e.has)),"multi-individual":$t(e,i)})}">${vt(e)&&a.state.toHome?R``:""}
`:"")(e,{battery:t,grid:o,individual:i,solar:a,newDur:n})} ${((e,{battery:t,grid:o,individual:i,solar:a,newDur:n})=>o.hasReturnToGrid&&a.has&&pt(e,a.state.toGrid||0)?H`
null==e?void 0:e.has)),"multi-individual":$t(e,i)})}">${vt(e)&&a.state.toGrid&&a.has?R``:""}
`:"")(e,{battery:t,grid:o,individual:i,solar:a,newDur:n})} ${((e,{battery:t,individual:o,solar:i,newDur:a})=>t.has&&i.has&&pt(e,i.state.toBattery||0)?H`
null==e?void 0:e.has)),"multi-individual":$t(e,o)})}">${vt(e)&&i.state.toBattery?R``:""}
`:"")(e,{battery:t,individual:i,solar:a,newDur:n})} ${((e,{battery:t,grid:o,individual:i,solar:a,newDur:n})=>o.has&&pt(e,o.state.fromGrid)?H`
null==e?void 0:e.has)),"multi-individual":$t(e,i)})}">${vt(e)&&o.state.toHome?R``:""}
`:"")(e,{battery:t,grid:o,individual:i,solar:a,newDur:n})} ${((e,{battery:t,grid:o,individual:i,newDur:a})=>t.has&&pt(e,t.state.toHome)?H`
null==e?void 0:e.has)),"multi-individual":$t(e,i)})}">${vt(e)&&t.state.toHome?R``:""}
`:"")(e,{battery:t,grid:o,individual:i,newDur:n})} ${((e,{battery:t,grid:o,individual:i,newDur:a})=>o.has&&t.has&&pt(e,Math.max(o.state.toBattery||0,t.state.toGrid||0))?H`
null==e?void 0:e.has)),"multi-individual":$t(e,i)})}">${vt(e)&&o.state.toBattery?R``:""} ${t.state.toGrid?R``:""}
`:"")(e,{battery:t,grid:o,individual:i,newDur:n})}`,At=(e,t)=>{var o;if("string"!=typeof(null==t?void 0:t.entity))return null;const i=qe(e,null===(o=null==t?void 0:t.secondary_info)||void 0===o?void 0:o.entity),a=null==i?void 0:i.state;return ye(a)?Number(a):a},Mt={field:void 0,entity:"",has:!1,state:null,displayZero:!1,displayZeroTolerance:0,icon:"",name:"",color:null,unit:void 0,unit_white_space:!1,invertAnimation:!1,showDirection:!1,secondary:{entity:null,template:null,has:!1,state:null,icon:null,unit:null,unit_white_space:!1,displayZero:!1,accept_negative:!1,displayZeroTolerance:0,decimals:null}},Pt=(e,t)=>{var o,i,a,n,r,l,s,d,c,u;if(!t||!(null==t?void 0:t.entity))return Mt;const h=t.entity,p=((e,t)=>{const o=null==t?void 0:t.entity;if(void 0===o)return null;const i=Oe(e,o);return Math.abs(i)})(e,t),v=(null==t?void 0:t.display_zero)||!1,_=(null==t?void 0:t.display_zero_tolerance)||0,m=((e,t,o)=>!!e||!!et(t,o))(v,p,_),f=p&&p<0,y=(null==t?void 0:t.inverted_animation)||!1,g=f?!y:y,b=(null==t?void 0:t.color)&&"string"==typeof(null==t?void 0:t.color)?null==t?void 0:t.color:null;return{field:t,entity:h,has:m,state:p,displayZero:v,displayZeroTolerance:_,icon:Je(e,t,"mdi:flash"),name:Qe(e,t,"Individual"),color:b,unit:null==t?void 0:t.unit_of_measurement,unit_white_space:(null==t?void 0:t.unit_white_space)||!1,decimals:null==t?void 0:t.decimals,invertAnimation:g,showDirection:(null==t?void 0:t.show_direction)||!1,secondary:{entity:(null===(o=null==t?void 0:t.secondary_info)||void 0===o?void 0:o.entity)||null,template:(null===(i=null==t?void 0:t.secondary_info)||void 0===i?void 0:i.template)||null,has:void 0!==(null===(a=null==t?void 0:t.secondary_info)||void 0===a?void 0:a.entity),state:At(e,t)||null,accept_negative:(null===(n=null==t?void 0:t.secondary_info)||void 0===n?void 0:n.accept_negative)||!1,icon:(null===(r=null==t?void 0:t.secondary_info)||void 0===r?void 0:r.icon)||null,unit:(null===(l=null==t?void 0:t.secondary_info)||void 0===l?void 0:l.unit_of_measurement)||null,unit_white_space:(null===(s=null==t?void 0:t.secondary_info)||void 0===s?void 0:s.unit_white_space)||!1,displayZero:(null===(d=null==t?void 0:t.secondary_info)||void 0===d?void 0:d.display_zero)||!1,displayZeroTolerance:(null===(c=null==t?void 0:t.secondary_info)||void 0===c?void 0:c.display_zero_tolerance)||0,decimals:(null===(u=null==t?void 0:t.secondary_info)||void 0===u?void 0:u.decimals)||null}}},zt=(e,t,o,i,a,n,r)=>{var l,s,d,c,u,h,p;const v=i.individual[n],_=(null===(l=null==a?void 0:a.secondary)||void 0===l?void 0:l.has)?rt(e,o,null===(s=null==a?void 0:a.secondary)||void 0===s?void 0:s.state,{unit:(null===(d=null==a?void 0:a.secondary)||void 0===d?void 0:d.unit)||void 0,unitWhiteSpace:null===(c=null==a?void 0:a.secondary)||void 0===c?void 0:c.unit_white_space,decimals:(null===(u=null==a?void 0:a.secondary)||void 0===u?void 0:u.decimals)||0,accept_negative:(null===(h=null==a?void 0:a.secondary)||void 0===h?void 0:h.accept_negative)||!1,watt_threshold:o.watt_threshold}):void 0;return H`${(()=>{var e,t,o,i,n;if(v)return!0;if(!0===(null===(e=null==a?void 0:a.secondary)||void 0===e?void 0:e.displayZero))return!0;if(!(null===(t=null==a?void 0:a.secondary)||void 0===t?void 0:t.state))return!1;if(!ye(null===(o=null==a?void 0:a.secondary)||void 0===o?void 0:o.state))return!0;const r=null!==(n=null===(i=null==a?void 0:a.secondary)||void 0===i?void 0:i.displayZeroTolerance)&&void 0!==n?n:0;return Number(a.secondary.state)>=r||a.secondary.accept_negative&&"number"==typeof Number(+a.secondary.state)})()?H`${ct({main:t,className:r,entityId:(null==a?void 0:a.secondary.entity)||void 0,icon:(null===(p=null==a?void 0:a.secondary)||void 0===p?void 0:p.icon)||void 0,value:_,template:i.individual[n]||void 0})}`:""}`},Dt=238.76104;!function(e){const t=window;t.customCards=t.customCards||[],t.customCards.push(Object.assign(Object.assign({},e),{preview:!0,documentationURL:"https://github.com/flixlix/power-flow-card-plus"}))}({type:"power-flow-card-plus",name:"Power Flow Card Plus",description:"An extended version of the power flow card with richer options, advanced features and a few small UI enhancements. Inspired by the Energy Dashboard."});let Tt=class extends se{constructor(){super(...arguments),this._config={},this._templateResults={},this._unsubRenderTemplates=new Map,this._width=0,this.previousDur={}}setConfig(e){var t,o,i,a,n,r,l,s,d,c,u,h;if(e.entities.individual1||e.entities.individual2)throw new Error("You are using an outdated configuration. Please update your configuration to the latest version.");if(!e.entities||!(null===(o=null===(t=e.entities)||void 0===t?void 0:t.battery)||void 0===o?void 0:o.entity)&&!(null===(a=null===(i=e.entities)||void 0===i?void 0:i.grid)||void 0===a?void 0:a.entity)&&!(null===(r=null===(n=e.entities)||void 0===n?void 0:n.solar)||void 0===r?void 0:r.entity))throw new Error("At least one entity for battery, grid or solar must be defined");if(this._config=Object.assign(Object.assign({},e),{kw_decimals:ge(e.kw_decimals,we.kilowattDecimals),min_flow_rate:ge(e.min_flow_rate,we.minFlowRate),max_flow_rate:ge(e.max_flow_rate,we.maxFlowRate),w_decimals:ge(e.w_decimals,we.wattDecimals),watt_threshold:ge(e.watt_threshold,we.wattThreshold),max_expected_power:ge(e.max_expected_power,we.maxExpectedPower),min_expected_power:ge(e.min_expected_power,we.minExpectedPower),display_zero_lines:{mode:null!==(s=null===(l=e.display_zero_lines)||void 0===l?void 0:l.mode)&&void 0!==s?s:we.displayZeroLines.mode,transparency:ge(null===(d=e.display_zero_lines)||void 0===d?void 0:d.transparency,we.displayZeroLines.transparency),grey_color:null!==(u=null===(c=e.display_zero_lines)||void 0===c?void 0:c.grey_color)&&void 0!==u?u:we.displayZeroLines.grey_color},individual_mode_config:{mode:"sort_power"}}),(null===(h=this._config.entities)||void 0===h?void 0:h.individual)&&this._config.entities.individual.length>4)throw new Error("Only 4 individual entities are supported")}connectedCallback(){super.connectedCallback(),this._tryConnectAll()}disconnectedCallback(){this._tryDisconnectAll()}static async getConfigElement(){return await Promise.resolve().then((function(){return Ba})),document.createElement("power-flow-card-plus-editor")}static getStubConfig(e){return function(e){function t(t,o){const i=e.states[t].attributes.friendly_name;return o.some((e=>t.includes(e)||(null==i?void 0:i.includes(e))))}const o=Object.keys(e.states).filter((t=>{const o=e.states[t];return o.state&&o.attributes&&"power"===o.attributes.device_class||o.entity_id.includes("power")})),i=["grid","utility","net","meter"],a=["solar","pv","photovoltaic","inverter"],n=["battery"],r=["battery_percent","battery_level","state_of_charge","soc","percentage"],l=o.filter((e=>t(e,i)))[0],s=o.filter((e=>t(e,a)))[0],d=o.filter((e=>t(e,n)))[0],c=Object.keys(e.states).filter((t=>{const o=e.states[t];return o&&o.state&&o.attributes&&"%"===o.attributes.unit_of_measurement})).filter((e=>t(e,r)))[0];return{entities:{battery:{entity:null!=d?d:"",state_of_charge:null!=c?c:""},grid:l?{entity:l}:void 0,solar:s?{entity:s,display_zero_state:!0}:void 0},clickable_entities:!0,display_zero_lines:!0,use_new_flow_rate_model:!0,w_decimals:we.wattDecimals,kw_decimals:we.kilowattDecimals,min_flow_rate:we.minFlowRate,max_flow_rate:we.maxFlowRate,max_expected_power:we.maxExpectedPower,min_expected_power:we.minExpectedPower,watt_threshold:we.wattThreshold,transparency_zero_lines:we.transparencyZeroLines}}(e)}getCardSize(){return 3}openDetails(e,t){if(e.stopPropagation(),!t||!this._config.clickable_entities)return;if(!((e,t)=>t in e.states)(this.hass,t))return;const o=new CustomEvent("hass-more-info",{composed:!0,detail:{entityId:t}});this.dispatchEvent(o)}render(){var e,t,o,i,a,n,r,l,s,d,c,u,h,p,v,_,m,f,y,g,b,w,x,k,S,$,C,E,A,M,P,z,D,T,O,N,j,B,L,I,F,U,G,V,W,Z,K,Y,X,q,J,Q,ee,te,oe,ie,ae,ne,re,le,se,de,ce,ue,he,pe,ve,_e,me,fe,ye,ge,be,we,xe,ke,Se,$e,Ce,Ee,Ae,Me,Pe,ze,Te,Ne,Le,Ie,He,Re,Ue,qe,et,dt,ct,mt,ft,yt,gt,bt,At,Mt,Tt,Ot,Nt,jt,Bt,Lt,It,Ht,Rt,Ft,Ut,Gt,Vt,Wt,Zt,Kt,Yt,Xt,qt,Jt,Qt,eo,to,oo,io,ao,no,ro,lo,so,co,uo,ho,po,vo,_o,mo,fo,yo,go,bo,wo,xo,ko,So,$o,Co,Eo,Ao,Mo,Po,zo,Do,To,Oo,No,jo,Bo,Lo,Io,Ho,Ro,Fo,Uo,Go,Vo,Wo,Zo,Ko,Yo,Xo,qo,Jo,Qo;if(!this._config||!this.hass)return H``;const{entities:ei}=this._config;this.style.setProperty("--clickable-cursor",this._config.clickable_entities?"pointer":"default");const ti=null,oi={entity:null===(e=ei.grid)||void 0===e?void 0:e.entity,has:void 0!==(null===(t=null==ei?void 0:ei.grid)||void 0===t?void 0:t.entity),hasReturnToGrid:"string"==typeof(null===(o=ei.grid)||void 0===o?void 0:o.entity)||!!(null===(a=null===(i=ei.grid)||void 0===i?void 0:i.entity)||void 0===a?void 0:a.production),state:{fromGrid:Ge(this.hass,this._config),toGrid:(ii=this.hass,ai=this._config,Fe(ii,ai,"grid")),toBattery:ti,toHome:ti},powerOutage:{has:void 0!==(null===(r=null===(n=ei.grid)||void 0===n?void 0:n.power_outage)||void 0===r?void 0:r.entity),isOutage:(ei.grid&&(null===(s=this.hass.states[null===(l=ei.grid.power_outage)||void 0===l?void 0:l.entity])||void 0===s?void 0:s.state))===(null!==(u=null===(c=null===(d=ei.grid)||void 0===d?void 0:d.power_outage)||void 0===c?void 0:c.state_alert)&&void 0!==u?u:"on"),icon:(null===(p=null===(h=ei.grid)||void 0===h?void 0:h.power_outage)||void 0===p?void 0:p.icon_alert)||"mdi:transmission-tower-off",name:null!==(m=null===(_=null===(v=ei.grid)||void 0===v?void 0:v.power_outage)||void 0===_?void 0:_.label_alert)&&void 0!==m?m:H`Power
Outage`,entityGenerator:null===(y=null===(f=ei.grid)||void 0===f?void 0:f.power_outage)||void 0===y?void 0:y.entity_generator},icon:Je(this.hass,ei.grid,"mdi:transmission-tower"),name:Qe(this.hass,ei.grid,this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.grid")),mainEntity:"object"==typeof(null===(g=ei.grid)||void 0===g?void 0:g.entity)?ei.grid.entity.consumption||ei.grid.entity.production:null===(b=ei.grid)||void 0===b?void 0:b.entity,color:{fromGrid:null===(x=null===(w=ei.grid)||void 0===w?void 0:w.color)||void 0===x?void 0:x.consumption,toGrid:null===(S=null===(k=ei.grid)||void 0===k?void 0:k.color)||void 0===S?void 0:S.production,icon_type:null===($=ei.grid)||void 0===$?void 0:$.color_icon,circle_type:null===(C=ei.grid)||void 0===C?void 0:C.color_circle},secondary:{entity:null===(A=null===(E=ei.grid)||void 0===E?void 0:E.secondary_info)||void 0===A?void 0:A.entity,decimals:null===(P=null===(M=ei.grid)||void 0===M?void 0:M.secondary_info)||void 0===P?void 0:P.decimals,template:null===(D=null===(z=ei.grid)||void 0===z?void 0:z.secondary_info)||void 0===D?void 0:D.template,has:void 0!==(null===(O=null===(T=ei.grid)||void 0===T?void 0:T.secondary_info)||void 0===O?void 0:O.entity),state:Ve(this.hass,this._config),icon:null===(j=null===(N=ei.grid)||void 0===N?void 0:N.secondary_info)||void 0===j?void 0:j.icon,unit:null===(L=null===(B=ei.grid)||void 0===B?void 0:B.secondary_info)||void 0===L?void 0:L.unit_of_measurement,unit_white_space:null===(F=null===(I=ei.grid)||void 0===I?void 0:I.secondary_info)||void 0===F?void 0:F.unit_white_space,accept_negative:(null===(G=null===(U=ei.grid)||void 0===U?void 0:U.secondary_info)||void 0===G?void 0:G.accept_negative)||!1,color:{type:null===(W=null===(V=ei.grid)||void 0===V?void 0:V.secondary_info)||void 0===W?void 0:W.color_value}}};var ii,ai;const ni={entity:null===(Z=ei.solar)||void 0===Z?void 0:Z.entity,has:void 0!==(null===(K=ei.solar)||void 0===K?void 0:K.entity),state:{total:We(this.hass,this._config),toHome:ti,toGrid:ti,toBattery:ti},icon:Je(this.hass,ei.solar,"mdi:solar-power"),name:Qe(this.hass,ei.solar,this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.solar")),secondary:{entity:null===(X=null===(Y=ei.solar)||void 0===Y?void 0:Y.secondary_info)||void 0===X?void 0:X.entity,decimals:null===(J=null===(q=ei.solar)||void 0===q?void 0:q.secondary_info)||void 0===J?void 0:J.decimals,template:null===(ee=null===(Q=ei.solar)||void 0===Q?void 0:Q.secondary_info)||void 0===ee?void 0:ee.template,has:void 0!==(null===(oe=null===(te=ei.solar)||void 0===te?void 0:te.secondary_info)||void 0===oe?void 0:oe.entity),accept_negative:(null===(ae=null===(ie=ei.solar)||void 0===ie?void 0:ie.secondary_info)||void 0===ae?void 0:ae.accept_negative)||!1,state:Ze(this.hass,this._config),icon:null===(re=null===(ne=ei.solar)||void 0===ne?void 0:ne.secondary_info)||void 0===re?void 0:re.icon,unit:null===(se=null===(le=ei.solar)||void 0===le?void 0:le.secondary_info)||void 0===se?void 0:se.unit_of_measurement,unit_white_space:null===(ce=null===(de=ei.solar)||void 0===de?void 0:de.secondary_info)||void 0===ce?void 0:ce.unit_white_space}},ri={entity:null===(ue=ei.battery)||void 0===ue?void 0:ue.entity,has:(()=>{var e,t,o,i,a;return!!(null===(e=ei.battery)||void 0===e?void 0:e.entity)&&("object"==typeof(null===(t=ei.battery)||void 0===t?void 0:t.entity)?(null===(o=ei.battery)||void 0===o?void 0:o.entity.consumption)||(null===(i=ei.battery)||void 0===i?void 0:i.entity.production):void 0!==(null===(a=ei.battery)||void 0===a?void 0:a.entity))})(),mainEntity:"object"==typeof(null===(he=ei.battery)||void 0===he?void 0:he.entity)?ei.battery.entity.consumption:null===(pe=ei.battery)||void 0===pe?void 0:pe.entity,name:Qe(this.hass,ei.battery,this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.battery")),icon:Je(this.hass,ei.battery,"mdi:battery-high"),state_of_charge:{state:Ke(this.hass,this._config),unit:(null===(ve=null==ei?void 0:ei.battery)||void 0===ve?void 0:ve.state_of_charge_unit)||"%",unit_white_space:(null===(_e=null==ei?void 0:ei.battery)||void 0===_e?void 0:_e.state_of_charge_unit_white_space)||!0,decimals:(null===(me=null==ei?void 0:ei.battery)||void 0===me?void 0:me.state_of_charge_decimals)||0},state:{toBattery:Ye(this.hass,this._config),fromBattery:Xe(this.hass,this._config),toGrid:0,toHome:0},color:{fromBattery:null===(ye=null===(fe=ei.battery)||void 0===fe?void 0:fe.color)||void 0===ye?void 0:ye.consumption,toBattery:null===(be=null===(ge=ei.battery)||void 0===ge?void 0:ge.color)||void 0===be?void 0:be.production,icon_type:void 0,circle_type:null===(we=ei.battery)||void 0===we?void 0:we.color_circle}},li={entity:null===(xe=ei.home)||void 0===xe?void 0:xe.entity,has:void 0!==(null===(ke=null==ei?void 0:ei.home)||void 0===ke?void 0:ke.entity),state:ti,icon:Je(this.hass,null==ei?void 0:ei.home,"mdi:home"),name:Qe(this.hass,null==ei?void 0:ei.home,this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.home")),secondary:{entity:null===($e=null===(Se=ei.home)||void 0===Se?void 0:Se.secondary_info)||void 0===$e?void 0:$e.entity,template:null===(Ee=null===(Ce=ei.home)||void 0===Ce?void 0:Ce.secondary_info)||void 0===Ee?void 0:Ee.template,has:void 0!==(null===(Me=null===(Ae=ei.home)||void 0===Ae?void 0:Ae.secondary_info)||void 0===Me?void 0:Me.entity),state:nt(this.hass,this._config),accept_negative:(null===(ze=null===(Pe=ei.home)||void 0===Pe?void 0:Pe.secondary_info)||void 0===ze?void 0:ze.accept_negative)||!1,unit:null===(Ne=null===(Te=ei.home)||void 0===Te?void 0:Te.secondary_info)||void 0===Ne?void 0:Ne.unit_of_measurement,unit_white_space:null===(Ie=null===(Le=ei.home)||void 0===Le?void 0:Le.secondary_info)||void 0===Ie?void 0:Ie.unit_white_space,icon:null===(Re=null===(He=ei.home)||void 0===He?void 0:He.secondary_info)||void 0===Re?void 0:Re.icon,decimals:null===(qe=null===(Ue=ei.home)||void 0===Ue?void 0:Ue.secondary_info)||void 0===qe?void 0:qe.decimals}},si=(null===(et=ei.individual)||void 0===et?void 0:et.map((e=>Pt(this.hass,e))))||[],di={entity:null===(dt=ei.fossil_fuel_percentage)||void 0===dt?void 0:dt.entity,name:Qe(this.hass,ei.fossil_fuel_percentage,this.hass.localize("card.label.non_fossil_fuel_percentage")),icon:Je(this.hass,ei.fossil_fuel_percentage,"mdi:leaf"),has:ot(this.hass,this._config),hasPercentage:it(this.hass,this._config),state:{power:ti},color:null===(ct=ei.fossil_fuel_percentage)||void 0===ct?void 0:ct.color,color_value:null===(mt=ei.fossil_fuel_percentage)||void 0===mt?void 0:mt.color_value,secondary:{entity:null===(yt=null===(ft=ei.fossil_fuel_percentage)||void 0===ft?void 0:ft.secondary_info)||void 0===yt?void 0:yt.entity,decimals:null===(bt=null===(gt=ei.fossil_fuel_percentage)||void 0===gt?void 0:gt.secondary_info)||void 0===bt?void 0:bt.decimals,template:null===(Mt=null===(At=ei.fossil_fuel_percentage)||void 0===At?void 0:At.secondary_info)||void 0===Mt?void 0:Mt.template,has:void 0!==(null===(Ot=null===(Tt=ei.fossil_fuel_percentage)||void 0===Tt?void 0:Tt.secondary_info)||void 0===Ot?void 0:Ot.entity),state:at(this.hass,this._config),accept_negative:(null===(jt=null===(Nt=ei.fossil_fuel_percentage)||void 0===Nt?void 0:Nt.secondary_info)||void 0===jt?void 0:jt.accept_negative)||!1,icon:null===(Lt=null===(Bt=ei.fossil_fuel_percentage)||void 0===Bt?void 0:Bt.secondary_info)||void 0===Lt?void 0:Lt.icon,unit:null===(Ht=null===(It=ei.fossil_fuel_percentage)||void 0===It?void 0:It.secondary_info)||void 0===Ht?void 0:Ht.unit_of_measurement,unit_white_space:null===(Ft=null===(Rt=ei.fossil_fuel_percentage)||void 0===Rt?void 0:Rt.secondary_info)||void 0===Ft?void 0:Ft.unit_white_space,color_value:null===(Gt=null===(Ut=ei.fossil_fuel_percentage)||void 0===Ut?void 0:Ut.secondary_info)||void 0===Gt?void 0:Gt.color_value}};oi.state.fromGrid=tt(oi.state.fromGrid,null===(Vt=ei.grid)||void 0===Vt?void 0:Vt.display_zero_tolerance),oi.state.toGrid=tt(oi.state.toGrid,null===(Wt=ei.grid)||void 0===Wt?void 0:Wt.display_zero_tolerance),ni.state.total=tt(ni.state.total,null===(Zt=ei.solar)||void 0===Zt?void 0:Zt.display_zero_tolerance),ri.state.fromBattery=tt(ri.state.fromBattery,null===(Kt=ei.battery)||void 0===Kt?void 0:Kt.display_zero_tolerance),ri.state.toBattery=tt(ri.state.toBattery,null===(Yt=ei.battery)||void 0===Yt?void 0:Yt.display_zero_tolerance),0===oi.state.fromGrid&&(oi.state.toHome=0,oi.state.toBattery=0),0===ni.state.total&&(ni.state.toGrid=0,ni.state.toBattery=0,ni.state.toHome=0),0===ri.state.fromBattery&&(ri.state.toGrid=0,ri.state.toHome=0),ni.has&&(ni.state.toHome=(null!==(Xt=ni.state.total)&&void 0!==Xt?Xt:0)-(null!==(qt=oi.state.toGrid)&&void 0!==qt?qt:0)-(null!==(Jt=ri.state.toBattery)&&void 0!==Jt?Jt:0));const ci=Math.max(null!==(eo=null===(Qt=ei.grid)||void 0===Qt?void 0:Qt.display_zero_tolerance)&&void 0!==eo?eo:0,null!==(oo=null===(to=ei.battery)||void 0===to?void 0:to.display_zero_tolerance)&&void 0!==oo?oo:0);if(null!==ni.state.toHome&&ni.state.toHome<0?(ri.has&&(oi.state.toBattery=Math.abs(ni.state.toHome),oi.state.toBattery>(null!==(io=oi.state.fromGrid)&&void 0!==io?io:0)&&(ri.state.toGrid=Math.min(oi.state.toBattery-(null!==(ao=oi.state.fromGrid)&&void 0!==ao?ao:0),0),oi.state.toBattery=oi.state.fromGrid)),ni.state.toHome=0):oi.state.toBattery=0,oi.state.toBattery=(null!==(no=oi.state.toBattery)&&void 0!==no?no:0)>ci?oi.state.toBattery:0,ri.has&&(ni.has?(ri.state.toGrid||(ri.state.toGrid=Math.max(0,(oi.state.toGrid||0)-(ni.state.total||0)-(ri.state.toBattery||0)-(oi.state.toBattery||0))),ni.state.toBattery=ri.state.toBattery-(oi.state.toBattery||0),(null===(ro=ei.solar)||void 0===ro?void 0:ro.display_zero_tolerance)&&ei.solar.display_zero_tolerance>=(ni.state.total||0)&&(ni.state.toBattery=0)):ri.state.toGrid=oi.state.toGrid||0,ri.state.toGrid=(ri.state.toGrid||0)>ci&&ri.state.toGrid||0,ri.state.toHome=(null!==(lo=ri.state.fromBattery)&&void 0!==lo?lo:0)-(null!==(so=ri.state.toGrid)&&void 0!==so?so:0)),oi.state.toHome=Math.max(oi.state.fromGrid-(null!==(co=oi.state.toBattery)&&void 0!==co?co:0),0),ni.has&&oi.state.toGrid&&(ni.state.toGrid=oi.state.toGrid-(null!==(uo=ri.state.toGrid)&&void 0!==uo?uo:0)),oi.powerOutage.isOutage&&(oi.state.fromGrid=oi.powerOutage.entityGenerator?Math.max(Oe(this.hass,oi.powerOutage.entityGenerator),0):0,oi.state.toHome=Math.max(oi.state.fromGrid-(null!==(ho=oi.state.toBattery)&&void 0!==ho?ho:0),0),oi.state.toGrid=0,ri.state.toGrid=0,ni.state.toGrid=0,oi.icon=oi.powerOutage.icon,di.has=!1,di.hasPercentage=!1),di.has){const e=1-(null!==(vo=De(this.hass,null===(po=ei.fossil_fuel_percentage)||void 0===po?void 0:po.entity))&&void 0!==vo?vo:0)/100;di.state.power=oi.state.toHome*e}const ui=(null==si?void 0:si.reduce(((e,t)=>e+(t.state||0)),0))||0,hi=Math.max(oi.state.toHome+(null!==(_o=ni.state.toHome)&&void 0!==_o?_o:0)+(null!==(mo=ri.state.toHome)&&void 0!==mo?mo:0),0),pi=ri.state.toHome?Dt*(ri.state.toHome/hi):0,vi=ni.state.toHome?Dt*(ni.state.toHome/hi):0,_i=di.state.power?Dt*(di.state.power/hi):0,mi=Dt*((hi-(null!==(fo=di.state.power)&&void 0!==fo?fo:0)-(null!==(yo=ri.state.toHome)&&void 0!==yo?yo:0)-(null!==(go=ni.state.toHome)&&void 0!==go?go:0))/hi),fi=(null===(bo=ei.home)||void 0===bo?void 0:bo.override_state)&&ei.home.entity?(null===(wo=ei.home)||void 0===wo?void 0:wo.subtract_individual)?rt(this.hass,this._config,Oe(this.hass,ei.home.entity)-ui,{unit:null===(xo=ei.home)||void 0===xo?void 0:xo.unit_of_measurement,unitWhiteSpace:null===(ko=ei.home)||void 0===ko?void 0:ko.unit_white_space,watt_threshold:this._config.watt_threshold}):rt(this.hass,this._config,Oe(this.hass,ei.home.entity),{unit:null===(So=ei.home)||void 0===So?void 0:So.unit_of_measurement,unitWhiteSpace:null===($o=ei.home)||void 0===$o?void 0:$o.unit_white_space,watt_threshold:this._config.watt_threshold}):(null===(Co=ei.home)||void 0===Co?void 0:Co.subtract_individual)?rt(this.hass,this._config,hi-ui||0,{unit:null===(Eo=ei.home)||void 0===Eo?void 0:Eo.unit_of_measurement,unitWhiteSpace:null===(Ao=ei.home)||void 0===Ao?void 0:Ao.unit_white_space,watt_threshold:this._config.watt_threshold}):rt(this.hass,this._config,hi,{unit:null===(Mo=ei.home)||void 0===Mo?void 0:Mo.unit_of_measurement,unitWhiteSpace:null===(Po=ei.home)||void 0===Po?void 0:Po.unit_white_space,watt_threshold:this._config.watt_threshold}),yi=oi.state.toHome+(null!==(zo=ni.state.toHome)&&void 0!==zo?zo:0)+(null!==(Do=ni.state.toGrid)&&void 0!==Do?Do:0)+(null!==(To=ni.state.toBattery)&&void 0!==To?To:0)+(null!==(Oo=ri.state.toHome)&&void 0!==Oo?Oo:0)+(null!==(No=oi.state.toBattery)&&void 0!==No?No:0)+(null!==(jo=ri.state.toGrid)&&void 0!==jo?jo:0);null===ri.state_of_charge.state?ri.icon="mdi:battery":ri.state_of_charge.state<=72&&ri.state_of_charge.state>44?ri.icon="mdi:battery-medium":ri.state_of_charge.state<=44&&ri.state_of_charge.state>16?ri.icon="mdi:battery-low":ri.state_of_charge.state<=16&&(ri.icon="mdi:battery-outline"),void 0!==(null===(Bo=ei.battery)||void 0===Bo?void 0:Bo.icon)&&(ri.icon=null===(Lo=ei.battery)||void 0===Lo?void 0:Lo.icon);const gi={batteryGrid:je(this._config,null!==(Ho=null!==(Io=oi.state.toBattery)&&void 0!==Io?Io:ri.state.toGrid)&&void 0!==Ho?Ho:0,yi),batteryToHome:je(this._config,null!==(Ro=ri.state.toHome)&&void 0!==Ro?Ro:0,yi),gridToHome:je(this._config,oi.state.toHome,yi),solarToBattery:je(this._config,null!==(Fo=ni.state.toBattery)&&void 0!==Fo?Fo:0,yi),solarToGrid:je(this._config,null!==(Uo=ni.state.toGrid)&&void 0!==Uo?Uo:0,yi),solarToHome:je(this._config,null!==(Go=ni.state.toHome)&&void 0!==Go?Go:0,yi),individual:(null==si?void 0:si.map((e=>{var t;return je(this._config,null!==(t=e.state)&&void 0!==t?t:0,ui)})))||[],nonFossil:je(this._config,null!==(Vo=di.state.power)&&void 0!==Vo?Vo:0,yi)};["batteryGrid","batteryToHome","gridToHome","solarToBattery","solarToGrid","solarToHome"].forEach((e=>{const t=this[`${e}Flow`];t&&this.previousDur[e]&&this.previousDur[e]!==gi[e]&&(t.pauseAnimations(),t.setCurrentTime(t.getCurrentTime()*(gi[e]/this.previousDur[e])),t.unpauseAnimations()),this.previousDur[e]=gi[e]}));const bi={battery:{value:pi,color:"var(--energy-battery-out-color)"},solar:{value:vi,color:"var(--energy-solar-color)"},grid:{value:mi,color:"var(--energy-grid-consumption-color)"},gridNonFossil:{value:_i,color:"var(--energy-non-fossil-color)"}},wi=Object.keys(bi).reduce(((e,t)=>bi[e].value>bi[t].value?e:t)),xi=e=>e?void 0===(null==e?void 0:e.state)?"":rt(this.hass,this._config,null==e?void 0:e.state,{decimals:null==e?void 0:e.decimals,unit:null==e?void 0:e.unit,unitWhiteSpace:null==e?void 0:e.unit_white_space,watt_threshold:this._config.watt_threshold}):"",ki=["left-top","left-bottom","right-top","right-bottom"],Si={gridSecondary:null===(Wo=this._templateResults.gridSecondary)||void 0===Wo?void 0:Wo.result,solarSecondary:null===(Zo=this._templateResults.solarSecondary)||void 0===Zo?void 0:Zo.result,homeSecondary:null===(Ko=this._templateResults.homeSecondary)||void 0===Ko?void 0:Ko.result,nonFossilFuelSecondary:null===(Yo=this._templateResults.nonFossilFuelSecondary)||void 0===Yo?void 0:Yo.result,individual:(null==si?void 0:si.map(((e,t)=>{var o;return null===(o=this._templateResults[`${ki[t]}Secondary`])||void 0===o?void 0:o.result})))||[]},$i=this._width>420;((e,{grid:t,solar:o,entities:i,individual:a,battery:n,homeSources:r,homeLargestSource:l,nonFossil:s,display_zero_lines_transparency:d,display_zero_lines_grey_color:c,isCardWideEnough:u})=>{var h,p,v,_,m,f,y,g,b,w,x,k,S,$,C,E,A,M,P,z,D,T,O,N;if(e.style.setProperty("--icon-grid-color","consumption"===t.color.icon_type?"var(--energy-grid-consumption-color)":"production"===t.color.icon_type?"var(--energy-grid-return-color)":!0===t.color.icon_type?(null!==(h=t.state.fromGrid)&&void 0!==h?h:0)>=(null!==(p=t.state.toGrid)&&void 0!==p?p:0)?"var(--energy-grid-consumption-color)":"var(--energy-grid-return-color)":"var(--primary-text-color)"),e.style.setProperty("--circle-grid-color","consumption"===t.color.circle_type?"var(--energy-grid-consumption-color)":"production"===t.color.circle_type?"var(--energy-grid-return-color)":!0===t.color.circle_type?(null!==(v=t.state.fromGrid)&&void 0!==v?v:0)>=(null!==(_=t.state.toGrid)&&void 0!==_?_:0)?"var(--energy-grid-consumption-color)":"var(--energy-grid-return-color)":"var(--energy-grid-consumption-color)"),void 0!==t.color.fromGrid&&("object"==typeof t.color.fromGrid&&(t.color.fromGrid=lt(t.color.fromGrid)),e.style.setProperty("--energy-grid-consumption-color",t.color.fromGrid||"#a280db")),void 0!==t.color.toGrid&&("object"==typeof t.color.toGrid&&(t.color.toGrid=lt(t.color.toGrid)),e.style.setProperty("--energy-grid-return-color",t.color.toGrid||"#a280db")),e.style.setProperty("--secondary-text-grid-color","consumption"===t.secondary.color.type?"var(--energy-grid-consumption-color)":"production"===t.secondary.color.type?"var(--energy-grid-return-color)":!0===t.secondary.color.type?(null!==(m=t.state.fromGrid)&&void 0!==m?m:0)>=(null!==(f=t.state.toGrid)&&void 0!==f?f:0)?"var(--energy-grid-consumption-color)":"var(--energy-grid-return-color)":"var(--primary-text-color)"),!1===(null===(y=i.grid)||void 0===y?void 0:y.color_value)?(e.style.setProperty("--text-grid-consumption-color","var(--primary-text-color)"),e.style.setProperty("--text-grid-return-color","var(--primary-text-color)")):(e.style.setProperty("--text-grid-consumption-color","var(--energy-grid-consumption-color)"),e.style.setProperty("--text-grid-return-color","var(--energy-grid-return-color)")),e.style.setProperty("--text-solar-color",(null===(g=i.solar)||void 0===g?void 0:g.color_value)?"var(--energy-solar-color)":"var(--primary-text-color)"),e.style.setProperty("--secondary-text-solar-color",(null===(w=null===(b=i.solar)||void 0===b?void 0:b.secondary_info)||void 0===w?void 0:w.color_value)?"var(--energy-solar-color)":"var(--primary-text-color)"),void 0!==(null===(x=i.solar)||void 0===x?void 0:x.color)){let t=null===(k=i.solar)||void 0===k?void 0:k.color;"object"==typeof t&&(t=lt(t)),e.style.setProperty("--energy-solar-color",t||"#ff9800")}e.style.setProperty("--icon-solar-color",(null===(S=i.solar)||void 0===S?void 0:S.color_icon)?"var(--energy-solar-color)":"var(--primary-text-color)"),void 0!==n.color.fromBattery&&("object"==typeof n.color.fromBattery&&(n.color.fromBattery=lt(n.color.fromBattery)),e.style.setProperty("--energy-battery-out-color",n.color.fromBattery||"#4db6ac")),void 0!==n.color.toBattery&&("object"==typeof n.color.toBattery&&(n.color.toBattery=lt(n.color.toBattery)),e.style.setProperty("--energy-battery-in-color",n.color.toBattery||"#a280db")),n.color.icon_type=null===($=i.battery)||void 0===$?void 0:$.color_icon,e.style.setProperty("--icon-battery-color","consumption"===n.color.icon_type?"var(--energy-battery-in-color)":"production"===n.color.icon_type?"var(--energy-battery-out-color)":!0===n.color.icon_type?n.state.fromBattery>=n.state.toBattery?"var(--energy-battery-out-color)":"var(--energy-battery-in-color)":"var(--primary-text-color)");const j=null===(C=i.battery)||void 0===C?void 0:C.color_state_of_charge_value;if(e.style.setProperty("--text-battery-state-of-charge-color","consumption"===j?"var(--energy-battery-in-color)":"production"===j?"var(--energy-battery-out-color)":!0===j?n.state.fromBattery>=n.state.toBattery?"var(--energy-battery-out-color)":"var(--energy-battery-in-color)":"var(--primary-text-color)"),e.style.setProperty("--circle-battery-color","consumption"===n.color.circle_type?"var(--energy-battery-in-color)":"production"===n.color.circle_type||!0===n.color.circle_type&&n.state.fromBattery>=n.state.toBattery?"var(--energy-battery-out-color)":"var(--energy-battery-in-color)"),!1===(null===(E=i.battery)||void 0===E?void 0:E.color_value)?(e.style.setProperty("--text-battery-in-color","var(--primary-text-color)"),e.style.setProperty("--text-battery-out-color","var(--primary-text-color)")):(e.style.setProperty("--text-battery-in-color","var(--energy-battery-in-color)"),e.style.setProperty("--text-battery-out-color","var(--energy-battery-out-color)")),void 0!==s.color&&("object"==typeof s.color&&(s.color=lt(s.color)),e.style.setProperty("--non-fossil-color",s.color||"var(--energy-non-fossil-color)")),e.style.setProperty("--icon-non-fossil-color",(null===(A=i.fossil_fuel_percentage)||void 0===A?void 0:A.color_icon)?"var(--non-fossil-color)":"var(--primary-text-color)"),e.style.setProperty("--text-non-fossil-color",(null===(M=i.fossil_fuel_percentage)||void 0===M?void 0:M.color_value)?"var(--non-fossil-color)":"var(--primary-text-color)"),e.style.setProperty("--secondary-text-non-fossil-color",(null===(z=null===(P=i.fossil_fuel_percentage)||void 0===P?void 0:P.secondary_info)||void 0===z?void 0:z.color_value)?"var(--non-fossil-color)":"var(--primary-text-color)"),e.style.setProperty("--secondary-text-home-color",(null===(T=null===(D=i.home)||void 0===D?void 0:D.secondary_info)||void 0===T?void 0:T.color_value)?"var(--text-home-color)":"var(--primary-text-color)"),e.style.setProperty("--icon-home-color",st(null===(O=i.home)||void 0===O?void 0:O.color_icon,r,l)),e.style.setProperty("--text-home-color",st(null===(N=i.home)||void 0===N?void 0:N.color_value,r,l)),e.style.setProperty("--battery-grid-line",t.state.toBattery?"var(--energy-grid-consumption-color)":"var(--energy-grid-return-color)"),e.style.setProperty("--transparency-unused-lines",d?d.toString():"0"),void 0!==c){let t=c;"object"==typeof t&&(t=lt(t)),e.style.setProperty("--greyed-out--line-color",t)}if(o.has&&(n.has?(e.style.setProperty("--lines-svg-not-flat-line-height","106%"),e.style.setProperty("--lines-svg-not-flat-line-top","-3%"),e.style.setProperty("--lines-svg-flat-width","calc(100% - 160px)"),e.style.setProperty("--lines-svg-flat-left","0"),e.style.setProperty("--lines-svg-not-flat-left","0")):(e.style.setProperty("--lines-svg-not-flat-line-top","-2%"),e.style.setProperty("--lines-svg-flat-width",u?"calc(100% - 154px)":"calc(100% - 157px)"),e.style.setProperty("--lines-svg-not-flat-width",u?"calc(103% - 172px)":"calc(103% - 169px)"),e.style.setProperty("--lines-svg-not-flat-left","3px"),e.style.setProperty("--lines-svg-flat-left","-3px"))),null==a?void 0:a.some((e=>e.has))){const t=(t,o)=>{var i;const a=["left-top","left-bottom","right-top","right-bottom"],n=(null==a?void 0:a[o])||"left-top";let r=null==t?void 0:t.color;"object"==typeof r&&(r=lt(r)),e.style.setProperty(`--individual-${n}-color`,r||["#d0cc5b","#964cb5","#b54c9d","#5bd0cc"][o]||"#d0cc5b"),e.style.setProperty(`--icon-individual-${n}-color`,!1!==(null==t?void 0:t.color_icon)?`var(--individual-${n}-color)`:"var(--primary-text-color)"),e.style.setProperty(`--text-individual-${n}-color`,(null==t?void 0:t.color_value)?`var(--individual-${n}-color)`:"var(--primary-text-color)"),e.style.setProperty(`--secondary-text-individual-${n}-color`,(null===(i=null==t?void 0:t.secondary_info)||void 0===i?void 0:i.color_value)?`var(--individual-${n}-color)`:"var(--primary-text-color)")};let o=0;a.forEach(((e,n)=>{a[n].has&&(t(i.individual[n],o),o++)}))}})(this,{grid:oi,solar:ni,battery:ri,display_zero_lines_grey_color:"grey_out"===(null===(Xo=this._config.display_zero_lines)||void 0===Xo?void 0:Xo.mode)?null===(qo=this._config.display_zero_lines)||void 0===qo?void 0:qo.grey_color:"",display_zero_lines_transparency:"transparency"===(null===(Jo=this._config.display_zero_lines)||void 0===Jo?void 0:Jo.mode)?null===(Qo=this._config.display_zero_lines)||void 0===Qo?void 0:Qo.transparency:"",entities:ei,homeLargestSource:wi,homeSources:bi,individual:si,nonFossil:di,isCardWideEnough:$i});const Ci=((e,t)=>{var o;if("sort_power"===(null===(o=e.individual_mode_config)||void 0===o?void 0:o.mode))return wt(t,0)})(this._config,si),Ei=xt(this._config,si),Ai=kt(this._config,si),Mi=St(this._config,si);return H`
${ni.has||(null==si?void 0:si.some((e=>null==e?void 0:e.has)))||di.hasPercentage?H`
${_t(this,this._config,{entities:ei,grid:oi,newDur:gi,nonFossil:di,templatesObj:Si})} ${ni.has?((e,t,{entities:o,solar:i,templatesObj:a})=>{var n;return H`
${i.name}
${ut(e.hass,e,t,a,i,"solar")} ${" "!==i.icon?H``:null} ${!1!==(null===(n=o.solar)||void 0===n?void 0:n.display_zero_state)||(i.state.total||0)>0?H`${rt(e.hass,t,i.state.total,{unit:i.state.unit,unitWhiteSpace:i.state.unit_white_space,decimals:i.state.decimals,watt_threshold:t.watt_threshold})}`:""}
`})(this,this._config,{entities:ei,solar:ni,templatesObj:Si}):(null==si?void 0:si.some((e=>null==e?void 0:e.has)))?H`
`:""} ${Ci?((e,t,{individualObj:o,templatesObj:i,displayState:a,newDur:n})=>{var r,l,s,d,c,u;if(!o)return H`
`;const h=(null===(l=null===(r=null==t?void 0:t.entities)||void 0===r?void 0:r.individual)||void 0===l?void 0:l.findIndex((e=>e.entity===o.entity)))||0,p=n.individual[h]||0;return H`
${o.name}
${zt(e.hass,e,t,i,o,h,"left-top")} ${" "!==o.icon?H``:null} ${!1!==(null===(s=null==o?void 0:o.field)||void 0===s?void 0:s.display_zero_state)||(o.state||0)>(null!==(d=o.displayZeroTolerance)&&void 0!==d?d:0)?H`${(null==o?void 0:o.showDirection)?H``:""}${a}`:""}
${pt(t,o.state||0)?H`${vt(t)&&o.state&&o.state>=(null!==(c=o.displayZeroTolerance)&&void 0!==c?c:0)?R``:""}`:""}
`})(this,this._config,{individualObj:Ci,displayState:xi(Ci),newDur:gi,templatesObj:Si}):H`
`} ${$t(this._config,si)?((e,t,{individualObj:o,templatesObj:i,displayState:a,newDur:n,battery:r,individualObjs:l})=>{var s,d,c,u,h,p;if(!o)return H`
`;const v=(null===(d=null===(s=null==t?void 0:t.entities)||void 0===s?void 0:s.individual)||void 0===d?void 0:d.findIndex((e=>e.entity===o.entity)))||-1;if(-1===v)return H`
`;const _=n.individual[v]||1.66,m=!!(null==r?void 0:r.has)||Ct(t,l);return H`
${o.name}
${zt(e.hass,e,t,i,o,v,"right-top")} ${" "!==o.icon?H``:null} ${!1!==(null===(c=null==o?void 0:o.field)||void 0===c?void 0:c.display_zero_state)||(o.state||0)>(null!==(u=o.displayZeroTolerance)&&void 0!==u?u:0)?H`${(null==o?void 0:o.showDirection)?H``:""}${a}`:""}
${pt(t,o.state||0)?H`
${vt(t)&&o.state&&o.state>=(null!==(h=o.displayZeroTolerance)&&void 0!==h?h:0)?R``:""}
`:""}
`})(this,this._config,{displayState:xi(Ai),individualObj:Ai,newDur:gi,templatesObj:Si,battery:ri,individualObjs:si}):H``}
`:H``}
${oi.has?((e,t,{entities:o,grid:i,templatesObj:a})=>{var n,r,l,s,d,c,u,h,p,v,_;return H`
${ut(e.hass,e,t,a,i,"grid")} ${" "!==i.icon?H``:null} ${("two_way"===(null===(n=o.grid)||void 0===n?void 0:n.display_state)||void 0===(null===(r=o.grid)||void 0===r?void 0:r.display_state)||"one_way_no_zero"===(null===(l=o.grid)||void 0===l?void 0:l.display_state)&&(null!==(s=i.state.toGrid)&&void 0!==s?s:0)>0||"one_way"===(null===(d=o.grid)||void 0===d?void 0:d.display_state)&&(null===i.state.fromGrid||0===i.state.fromGrid)&&0!==i.state.toGrid)&&null!==i.state.toGrid&&!i.powerOutage.isOutage?H`${rt(e.hass,t,i.state.toGrid,{unit:i.unit,unitWhiteSpace:i.unit_white_space,decimals:i.decimals,watt_threshold:t.watt_threshold})}`:null} ${("two_way"===(null===(c=o.grid)||void 0===c?void 0:c.display_state)||void 0===(null===(u=o.grid)||void 0===u?void 0:u.display_state)||"one_way_no_zero"===(null===(h=o.grid)||void 0===h?void 0:h.display_state)&&i.state.fromGrid>0||"one_way"===(null===(p=o.grid)||void 0===p?void 0:p.display_state)&&(null===i.state.toGrid||0===i.state.toGrid))&&null!==i.state.fromGrid&&!i.powerOutage.isOutage||i.powerOutage.isOutage&&i.powerOutage.entityGenerator?H`${rt(e.hass,t,i.state.fromGrid,{unit:i.unit,unitWhiteSpace:i.unit_white_space,decimals:i.decimals,watt_threshold:t.watt_threshold})}`:""} ${(null===(v=i.powerOutage)||void 0===v?void 0:v.isOutage)&&!(null===(_=i.powerOutage)||void 0===_?void 0:_.entityGenerator)?H`${i.powerOutage.name}`:""}
${i.name}
`})(this,this._config,{entities:ei,grid:oi,templatesObj:Si}):H`
`}
${((e,t,{home:o,entities:i,templatesObj:a,homeUsageToDisplay:n,homeSolarCircumference:r,circleCircumference:l,homeBatteryCircumference:s,homeNonFossilCircumference:d,homeGridCircumference:c,individual:u})=>{const h=u.filter((e=>e.has)).length<=1;return H`
${ut(e.hass,e,t,a,o,"home")} ${" "!==o.icon?H``:null} ${n} ${void 0!==r?R``:""} ${s?R``:""} ${void 0!==d?R``:""}
${h?H`${o.name}`:H``}
`})(this,this._config,{circleCircumference:Dt,entities:ei,grid:oi,home:li,homeBatteryCircumference:pi,homeGridCircumference:mi,homeNonFossilCircumference:_i,homeSolarCircumference:vi,newDur:gi,templatesObj:Si,homeUsageToDisplay:fi,individual:si})} ${$t(this._config,si)?H`
`:H``}
${ri.has||Ct(this._config,si)?H`
${ri.has?((e,t,{battery:o,entities:i})=>{var a,n,r,l,s,d,c,u,h,p;return H`
${null!==o.state_of_charge.state&&!1!==(null===(a=i.battery)||void 0===a?void 0:a.show_state_of_charge)?H`${rt(e.hass,t,o.state_of_charge.state,{unit:null!==(n=o.state_of_charge.unit)&&void 0!==n?n:"%",unitWhiteSpace:o.state_of_charge.unit_white_space,decimals:o.state_of_charge.decimals,accept_negative:void 0,watt_threshold:t.watt_threshold})}`:null} ${" "!==o.icon?H``:null} ${"two_way"===(null===(r=i.battery)||void 0===r?void 0:r.display_state)||void 0===(null===(l=i.battery)||void 0===l?void 0:l.display_state)||"one_way_no_zero"===(null===(s=i.battery)||void 0===s?void 0:s.display_state)&&o.state.toBattery>0||"one_way"===(null===(d=i.battery)||void 0===d?void 0:d.display_state)&&0!==o.state.toBattery?H`${rt(e.hass,t,o.state.toBattery,{unit:o.unit,unitWhiteSpace:o.unit_white_space,decimals:o.decimals,watt_threshold:t.watt_threshold})}`:""} ${"two_way"===(null===(c=i.battery)||void 0===c?void 0:c.display_state)||void 0===(null===(u=i.battery)||void 0===u?void 0:u.display_state)||"one_way_no_zero"===(null===(h=i.battery)||void 0===h?void 0:h.display_state)&&o.state.fromBattery>0||"one_way"===(null===(p=i.battery)||void 0===p?void 0:p.display_state)&&(0===o.state.toBattery||0!==o.state.fromBattery)?H`${rt(e.hass,t,o.state.fromBattery,{unit:o.unit,unitWhiteSpace:o.unit_white_space,decimals:o.decimals,watt_threshold:t.watt_threshold})}`:""}
${o.name}
`})(this,this._config,{battery:ri,entities:ei}):H`
`} ${Ei?((e,t,o,{individualObj:i,templatesObj:a,displayState:n,newDur:r})=>{var l,s,d,c,u,h;if(!i)return H`
`;const p=(null===(s=null===(l=null==o?void 0:o.entities)||void 0===l?void 0:l.individual)||void 0===s?void 0:s.findIndex((e=>e.entity===i.entity)))||0,v=r.individual[p]||0;return H`
${pt(o,(null==i?void 0:i.state)||0)?H`${vt(o)&&(null==i?void 0:i.state)&&i.state>=(null!==(d=i.displayZeroTolerance)&&void 0!==d?d:0)?R``:""}`:H``}
${zt(t,e,o,a,i,p,"left-bottom")} ${" "!==(null==i?void 0:i.icon)?H``:null} ${!1!==(null===(u=null==i?void 0:i.field)||void 0===u?void 0:u.display_zero_state)||((null==i?void 0:i.state)||0)>(null!==(h=i.displayZeroTolerance)&&void 0!==h?h:0)?H`${(null==i?void 0:i.showDirection)?H``:""}${n}`:""}
${null==i?void 0:i.name}
`})(this,this.hass,this._config,{displayState:xi(Ei),individualObj:Ei,newDur:gi,templatesObj:Si}):H`
`} ${$t(this._config,si)?((e,t,{individualObj:o,templatesObj:i,displayState:a,newDur:n,battery:r,individualObjs:l})=>{var s,d,c,u,h,p;if(!o)return H`
`;const v=(null===(d=null===(s=null==t?void 0:t.entities)||void 0===s?void 0:s.individual)||void 0===d?void 0:d.findIndex((e=>e.entity===o.entity)))||-1;if(-1===v)return H`
`;const _=n.individual[v]||1.66;return(null==r?void 0:r.has)||Ct(t,l),H`
${zt(e.hass,e,t,i,o,v,"right-bottom")} ${" "!==o.icon?H``:null} ${!1!==(null===(c=null==o?void 0:o.field)||void 0===c?void 0:c.display_zero_state)||(o.state||0)>(null!==(u=o.displayZeroTolerance)&&void 0!==u?u:0)?H`${(null==o?void 0:o.showDirection)?H``:""}${a}`:""}
${o.name} ${pt(t,o.state||0)?H`
${vt(t)&&o.state&&o.state>=(null!==(h=o.displayZeroTolerance)&&void 0!==h?h:0)?R``:""}
`:""}
`})(this,this._config,{displayState:xi(Mi),individualObj:Mi,newDur:gi,templatesObj:Si,battery:ri,individualObjs:si}):H``}
`:H`
`} ${Et(this._config,{battery:ri,grid:oi,individual:si,newDur:gi,solar:ni})}
${((e,t)=>e.dashboard_link||e.second_dashboard_link?H``:H``)(this._config,this.hass)}
`}updated(e){var t;if(super.updated(e),!this._config||!this.hass)return;const o=null===(t=null==this?void 0:this.shadowRoot)||void 0===t?void 0:t.querySelector("#power-flow-card-plus"),i=o?getComputedStyle(o).getPropertyValue("width"):"0px";this._width=parseInt(i.replace("px",""),10),this._tryConnectAll()}_tryConnectAll(){var e,t,o,i,a,n,r,l,s;const{entities:d}=this._config,c={gridSecondary:null===(t=null===(e=d.grid)||void 0===e?void 0:e.secondary_info)||void 0===t?void 0:t.template,solarSecondary:null===(i=null===(o=d.solar)||void 0===o?void 0:o.secondary_info)||void 0===i?void 0:i.template,homeSecondary:null===(n=null===(a=d.home)||void 0===a?void 0:a.secondary_info)||void 0===n?void 0:n.template,individualSecondary:null===(r=d.individual)||void 0===r?void 0:r.map((e=>{var t;return null===(t=e.secondary_info)||void 0===t?void 0:t.template})),nonFossilFuelSecondary:null===(s=null===(l=d.fossil_fuel_percentage)||void 0===l?void 0:l.secondary_info)||void 0===s?void 0:s.template};for(const[e,t]of Object.entries(c))if(t)if(Array.isArray(t)){const e=["left-top","left-bottom","right-top","right-bottom"];t.forEach(((t,o)=>{t&&this._tryConnect(t,`${e[o]}Secondary`)}))}else this._tryConnect(t,e)}async _tryConnect(e,t){var o,i,a,n,r,l;if(this.hass&&this._config&&void 0===(null===(o=this._unsubRenderTemplates)||void 0===o?void 0:o.get(t))&&""!==e)try{const o=(n=this.hass.connection,r=e=>{this._templateResults[t]=e},l={template:e,entity_ids:this._config.entity_id,variables:{config:this._config,user:this.hass.user.name},strict:!0},n.subscribeMessage((e=>r(e)),Object.assign({type:"render_template"},l)));null===(i=this._unsubRenderTemplates)||void 0===i||i.set(t,o),await o}catch(o){this._templateResults=Object.assign(Object.assign({},this._templateResults),{[t]:{result:e,listeners:{all:!1,domains:[],entities:[],time:!1}}}),null===(a=this._unsubRenderTemplates)||void 0===a||a.delete(t)}}async _tryDisconnectAll(){var e,t,o,i,a,n,r;const{entities:l}=this._config,s={gridSecondary:null===(t=null===(e=l.grid)||void 0===e?void 0:e.secondary_info)||void 0===t?void 0:t.template,solarSecondary:null===(i=null===(o=l.solar)||void 0===o?void 0:o.secondary_info)||void 0===i?void 0:i.template,homeSecondary:null===(n=null===(a=l.home)||void 0===a?void 0:a.secondary_info)||void 0===n?void 0:n.template,individualSecondary:null===(r=l.individual)||void 0===r?void 0:r.map((e=>{var t;return null===(t=e.secondary_info)||void 0===t?void 0:t.template}))};for(const[e,t]of Object.entries(s))t&&this._tryDisconnect(e)}async _tryDisconnect(e){var t,o;const i=null===(t=this._unsubRenderTemplates)||void 0===t?void 0:t.get(e);if(i)try{(await i)(),null===(o=this._unsubRenderTemplates)||void 0===o||o.delete(e)}catch(e){if("not_found"!==e.code&&"template_error"!==e.code)throw e}}};Tt.styles=be,e([pe({attribute:!1})],Tt.prototype,"hass",void 0),e([ve()],Tt.prototype,"_config",void 0),e([ve()],Tt.prototype,"_templateResults",void 0),e([ve()],Tt.prototype,"_unsubRenderTemplates",void 0),e([ve()],Tt.prototype,"_width",void 0),e([_e("#battery-grid-flow")],Tt.prototype,"batteryGridFlow",void 0),e([_e("#battery-home-flow")],Tt.prototype,"batteryToHomeFlow",void 0),e([_e("#grid-home-flow")],Tt.prototype,"gridToHomeFlow",void 0),e([_e("#solar-battery-flow")],Tt.prototype,"solarToBatteryFlow",void 0),e([_e("#solar-grid-flow")],Tt.prototype,"solarToGridFlow",void 0),e([_e("#solar-home-flow")],Tt.prototype,"solarToHomeFlow",void 0),Tt=e([ce("power-flow-card-plus")],Tt);class Ot extends TypeError{constructor(e,t){let o;const{message:i,explanation:a,...n}=e,{path:r}=e,l=0===r.length?i:`At path: ${r.join(".")} -- ${i}`;super(a??l),null!=a&&(this.cause=l),Object.assign(this,n),this.name=this.constructor.name,this.failures=()=>o??(o=[e,...t()])}}function Nt(e){return"object"==typeof e&&null!=e}function jt(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Bt(e,t,o,i){if(!0===e)return;!1===e?e={}:"string"==typeof e&&(e={message:e});const{path:a,branch:n}=t,{type:r}=o,{refinement:l,message:s=`Expected a value of type \`${r}\`${l?` with refinement \`${l}\``:""}, but received: \`${jt(i)}\``}=e;return{value:i,type:r,refinement:l,key:a[a.length-1],path:a,branch:n,...e,message:s}}function*Lt(e,t,o,i){(function(e){return Nt(e)&&"function"==typeof e[Symbol.iterator]})(e)||(e=[e]);for(const a of e){const e=Bt(a,t,o,i);e&&(yield e)}}function*It(e,t,o={}){const{path:i=[],branch:a=[e],coerce:n=!1,mask:r=!1}=o,l={path:i,branch:a};if(n&&(e=t.coercer(e,l),r&&"type"!==t.type&&Nt(t.schema)&&Nt(e)&&!Array.isArray(e)))for(const o in e)void 0===t.schema[o]&&delete e[o];let s="valid";for(const i of t.validator(e,l))i.explanation=o.message,s="not_valid",yield[i,void 0];for(let[d,c,u]of t.entries(e,l)){const t=It(c,u,{path:void 0===d?i:[...i,d],branch:void 0===d?a:[...a,c],coerce:n,mask:r,message:o.message});for(const o of t)o[0]?(s=null!=o[0].refinement?"not_refined":"not_valid",yield[o[0],void 0]):n&&(c=o[1],void 0===d?e=c:e instanceof Map?e.set(d,c):e instanceof Set?e.add(c):Nt(e)&&(void 0!==c||d in e)&&(e[d]=c))}if("not_valid"!==s)for(const i of t.refiner(e,l))i.explanation=o.message,s="not_refined",yield[i,void 0];"valid"===s&&(yield[void 0,e])}class Ht{constructor(e){const{type:t,schema:o,validator:i,refiner:a,coercer:n=(e=>e),entries:r=function*(){}}=e;this.type=t,this.schema=o,this.entries=r,this.coercer=n,this.validator=i?(e,t)=>Lt(i(e,t),t,this,e):()=>[],this.refiner=a?(e,t)=>Lt(a(e,t),t,this,e):()=>[]}assert(e,t){return Rt(e,this,t)}create(e,t){return function(e,t,o){const i=Ft(e,t,{coerce:!0,message:o});if(i[0])throw i[0];return i[1]}(e,this,t)}is(e){return function(e,t){const o=Ft(e,t);return!o[0]}(e,this)}mask(e,t){return function(e,t,o){const i=Ft(e,t,{coerce:!0,mask:!0,message:o});if(i[0])throw i[0];return i[1]}(e,this,t)}validate(e,t={}){return Ft(e,this,t)}}function Rt(e,t,o){const i=Ft(e,t,{message:o});if(i[0])throw i[0]}function Ft(e,t,o={}){const i=It(e,t,o),a=function(e){const{done:t,value:o}=e.next();return t?void 0:o}(i);if(a[0]){const e=new Ot(a[0],(function*(){for(const e of i)e[0]&&(yield e[0])}));return[e,void 0]}return[void 0,a[1]]}function Ut(e,t){return new Ht({type:e,schema:null,validator:t})}function Gt(){return Ut("any",(()=>!0))}function Vt(){return Ut("boolean",(e=>"boolean"==typeof e))}function Wt(){return Ut("integer",(e=>"number"==typeof e&&!isNaN(e)&&Number.isInteger(e)||`Expected an integer, but received: ${jt(e)}`))}function Zt(){return Ut("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${jt(e)}`))}function Kt(e){const t=e?Object.keys(e):[],o=Ut("never",(()=>!1));return new Ht({type:"object",schema:e||null,*entries(i){if(e&&Nt(i)){const a=new Set(Object.keys(i));for(const o of t)a.delete(o),yield[o,i[o],e[o]];for(const e of a)yield[e,i[e],o]}},validator:e=>Nt(e)||`Expected an object, but received: ${jt(e)}`,coercer:e=>Nt(e)?{...e}:e})}function Yt(e){return new Ht({...e,validator:(t,o)=>void 0===t||e.validator(t,o),refiner:(t,o)=>void 0===t||e.refiner(t,o)})}function Xt(){return Ut("string",(e=>"string"==typeof e||`Expected a string, but received: ${jt(e)}`))}var qt=Number.isNaN||function(e){return"number"==typeof e&&e!=e};function Jt(e,t){if(e.length!==t.length)return!1;for(var o=0;oe[t]),Wo[t])}catch(e){return}}function Yo(e){let t=Ko(e,(localStorage.getItem("selectedLanguage")||"en").replace(/['"]+/g,"").replace("-","_"));return t||(t=Ko(e,Zo)),null!=t?t:e}function Xo(){return{type:"expandable",title:Yo("editor.combined"),schema:[{name:"entity",selector:{entity:{}}}]}}function qo(){return{type:"expandable",title:Yo("editor.separated"),name:"entity",schema:[{name:"consumption",label:"Consumption Entity",selector:{entity:{}}},{name:"production",label:"Production Entity",selector:{entity:{}}}]}}const Jo={name:"color",title:Yo("editor.custom_colors"),type:"expandable",schema:[{type:"grid",column_min_width:"200px",schema:[{name:"consumption",label:"Consumption",selector:{color_rgb:{}}},{name:"production",label:"Production",selector:{color_rgb:{}}}]}]},Qo=[{name:"entity",selector:{entity:{}}},{name:"template",label:"Template (overrides entity, save to update)",selector:{template:{}}},{type:"grid",column_min_width:"200px",schema:[{name:"icon",selector:{icon:{}}},{name:"unit_of_measurement",label:"Unit of Measurement",selector:{text:{}}},{name:"decimals",label:"Decimals",selector:{number:{mode:"box",min:0,max:10,step:1}}},{name:"color_value",label:"Color Value",selector:{boolean:{}}},{name:"unit_white_space",label:"Unit White Space",selector:{boolean:{}}},{name:"display_zero",label:"Display Zero",selector:{boolean:{}}},{name:"accept_negative",label:"Accept Negative",selector:{boolean:{}}},{name:"display_zero_tolerance",label:"Display Zero Tolerance",selector:{number:{mode:"box",min:0,max:1e6,step:.1}}}]}],ei=[{name:"color_icon",label:"Color of Icon",selector:{select:{options:[{value:!1,label:"Do not Color"},{value:!0,label:"Color dynamically"},{value:"production",label:"Production"},{value:"consumption",label:"Consumption"}],custom_value:!0}}},{name:"color_circle",label:"Color of Circle",selector:{select:{options:[{value:!0,label:"Color dynamically"},{value:!1,label:"Consumption"},{value:"production",label:"Production"}],custom_value:!0}}},{name:"display_zero_tolerance",label:"Display Zero Tolerance",selector:{number:{min:0,max:1e6,step:1,mode:"box"}}},{name:"display_state",label:"Display State",selector:{select:{options:[{value:"two_way",label:"Two Way"},{value:"one_way_no_zero",label:"One Way"},{value:"one_way",label:"One Way (Show Zero)"}],custom_value:!0}}}];function ti(e){const t={type:"grid",column_min_width:"200px",schema:[{name:"name",selector:{text:{}}},{name:"icon",selector:{icon:{}}}]};return"battery"!==e&&"grid"!==e||t.schema.push(...ei),t}const oi=Object.assign(Object.assign({},ti("grid")),{schema:[...ti("grid").schema,{name:"invert_state",label:"Invert State",selector:{boolean:{}}},{name:"use_metadata",label:"Use Metadata",selector:{boolean:{}}},{name:"color_value",label:"Color of Value",selector:{boolean:{}}}]}),ii=[Xo(),qo(),oi,Jo,{title:Yo("editor.secondary_info"),name:"secondary_info",type:"expandable",schema:Qo},{title:Yo("editor.power_outage"),name:"power_outage",type:"expandable",schema:[{type:"grid",column_min_width:"200px",schema:[{name:"entity",selector:{entity:{}}},{name:"entity_generator",label:"Generator Entity",selector:{entity:{}}},{name:"label_alert",label:"Outage Label",selector:{text:{}}},{name:"icon_alert",label:"Outage Icon",selector:{icon:{}}},{name:"state_alert",label:"Outage State",selector:{text:{}}}]}]}],ai=Object.assign(Object.assign({},ti("battery")),{schema:[...ti("battery").schema,{name:"invert_state",label:"Invert State",selector:{boolean:{}}},{name:"color_value",label:"Color of Value",selector:{boolean:{}}},{name:"use_metadata",label:"Use Metadata",selector:{boolean:{}}}]}),ni=[Xo(),qo(),{title:Yo("editor.state_of_charge"),name:"",type:"expandable",schema:[{name:"state_of_charge",label:"State of Charge Entity",selector:{entity:{}}},{name:"",type:"grid",column_min_width:"200px",schema:[{name:"state_of_charge_unit",label:"Unit",selector:{text:{}}},{name:"state_of_charge_unit_white_space",label:"Unit White Space",selector:{boolean:{}}},{name:"state_of_charge_decimals",label:"Decimals",selector:{number:{mode:"box",min:0,max:4,step:1}}},{name:"show_state_of_charge",label:"Show State of Charge",selector:{boolean:{}}},{name:"color_state_of_charge_value",label:"Color of Value",selector:{select:{options:[{value:!1,label:"Do Not Color"},{value:!0,label:"Color dynamically"},{value:"consumption",label:"Consumption"},{value:"production",label:"Production"}],custom_value:!0}}}]}]},ai,Jo],ri=[{name:"entity",selector:{entity:{}}},Object.assign(Object.assign({},ti()),{schema:[...ti().schema,{name:"color_value",label:"Color Value",selector:{boolean:{}}},{name:"color_icon",label:"Color Icon",selector:{boolean:{}}},{name:"display_zero_state",label:"Display State When Zero?",selector:{boolean:{}}},{name:"display_zero_tolerance",label:"Display Zero Tolerance",selector:{number:{mode:"box",min:0,max:1e6,step:.1}}},{name:"invert_state",label:"Invert State",selector:{boolean:{}}},{name:"use_metadata",label:"Use Metadata",selector:{boolean:{}}}]}),{name:"color",label:"Color",selector:{color_rgb:{}}},{title:Yo("editor.secondary_info"),name:"secondary_info",type:"expandable",schema:Qo}],li=[{name:"entity",selector:{entity:{}}},Object.assign(Object.assign({},ti()),{schema:[...ti().schema,{name:"color_value",label:"Color Value",selector:{boolean:{}}},{name:"color_icon",label:"Color Icon",selector:{boolean:{}}},{name:"display_zero",label:"Display Zero",selector:{boolean:{}}},{name:"display_zero_tolerance",label:"Display Zero Tolerance",selector:{number:{mode:"box",min:0,max:1e6,step:.1}}},{name:"display_zero_state",label:"Display Zero State",selector:{boolean:{}}},{name:"unit_of_measurement",label:"Unit of Measurement",selector:{text:{}}},{name:"calculate_flow_rate",label:"Calculate Flow Rate",selector:{boolean:{}}},{name:"decimals",label:"Decimals",selector:{number:{mode:"box",min:0,max:4,step:1}}},{name:"inverted_animation",label:"Invert Animation",selector:{boolean:{}}},{name:"show_direction",label:"Show Direction",selector:{boolean:{}}},{name:"unit_white_space",label:"Unit White Space",selector:{boolean:{}}},{name:"use_metadata",label:"Use Metadata",selector:{boolean:{}}}]}),{name:"color",label:"Color",selector:{color_rgb:{}}},{title:Yo("editor.secondary_info"),name:"secondary_info",type:"expandable",schema:Qo}],si=[{name:"entity",selector:{entity:{}}},Object.assign(Object.assign({},ti()),{schema:[...ti().schema,{name:"state_type",label:"State Type",selector:{select:{options:[{value:"power",label:"Power"},{value:"percentage",label:"Percentage"}],custom_value:!0}}},{name:"color_value",label:"Color Value",selector:{boolean:{}}},{name:"color_icon",label:"Color Icon",selector:{boolean:{}}},{name:"display_zero",label:"Display Zero",selector:{boolean:{}}},{name:"display_zero_tolerance",label:"Display Zero Tolerance",selector:{number:{mode:"box",min:0,max:1e6,step:.1}}},{name:"display_zero_state",label:"Display Zero State",selector:{boolean:{}}},{name:"unit_white_space",label:"Unit White Space",selector:{boolean:{}}},{name:"use_metadata",label:"Use Metadata",selector:{boolean:{}}}]}),{name:"color",label:"Color",selector:{color_rgb:{}}},{title:Yo("editor.secondary_info"),name:"secondary_info",type:"expandable",schema:Qo}],di=[{name:"entity",selector:{entity:{}}},Object.assign(Object.assign({},ti()),{schema:[...ti().schema,{name:"color_value",label:"Color Value",selector:{select:{options:[{value:!0,label:"Color dynamically"},{value:!1,label:"Do Not Color"},{value:"solar",label:"Solar"},{value:"grid",label:"Grid"},{value:"battery",label:"Battery"}],custom_value:!0}}},{name:"color_icon",label:"Color Icon",selector:{select:{options:[{value:!0,label:"Color dynamically"},{value:!1,label:"Do Not Color"},{value:"solar",label:"Solar"},{value:"grid",label:"Grid"},{value:"battery",label:"Battery"}],custom_value:!0}}},{name:"subtract_individual",label:"Subtract Individual",selector:{boolean:{}}},{name:"override_state",label:"Override State (With Home Entity)",selector:{boolean:{}}},{name:"use_metadata",label:"Use Metadata",selector:{boolean:{}}}]}),{title:Yo("editor.secondary_info"),name:"secondary_info",type:"expandable",schema:Qo}],ci={name:"grey_color",selector:{color_rgb:{}}},ui={name:"transparency",selector:{number:{min:0,max:100,step:1,mode:"box"}}},hi={name:"",type:"grid",column_min_width:"200px",schema:[ui,ci]},pi=e=>{switch(e){case"grey_out":return ci;case"transparency":return ui;case"custom":return hi;default:return[]}},vi=Qt(((e,t)=>[{name:"display_zero_lines",type:"grid",column_min_width:"400px",schema:[{name:"mode",selector:{select:{mode:"dropdown",options:[{value:"show",label:e("editor.show")},{value:"hide",label:e("editor.hide")},{value:"transparency",label:e("editor.transparency")},{value:"grey_out",label:e("editor.grey_out")},{value:"custom",label:e("editor.custom")}]}}},pi(t)]}]));var _i="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z";const mi=function(...e){const t="type"===e[0].type,o=e.map((e=>e.schema)),i=Object.assign({},...o);return t?function(e){const t=Object.keys(e);return new Ht({type:"type",schema:e,*entries(o){if(Nt(o))for(const i of t)yield[i,o[i],e[i]]},validator:e=>Nt(e)||`Expected an object, but received: ${jt(e)}`,coercer:e=>Nt(e)?{...e}:e})}(i):Kt(i)}(Kt({type:Xt(),view_layout:Gt()}),Kt({title:Yt(Xt()),theme:Yt(Xt()),dashboard_link:Yt(Xt()),dashboard_link_label:Yt(Xt()),second_dashboard_link:Yt(Xt()),second_dashboard_link_label:Yt(Xt()),inverted_entities:Yt(Gt()),w_decimals:Yt(Wt()),kw_decimals:Yt(Wt()),min_flow_rate:Yt(Zt()),max_flow_rate:Yt(Zt()),min_expected_power:Yt(Zt()),max_expected_power:Yt(Zt()),watt_threshold:Yt(Zt()),clickable_entities:Yt(Vt()),transparency_zero_lines:Yt(Zt()),greyout_zero_lines:Yt(Vt()),display_zero_lines:Yt(Gt()),use_new_flow_rate_model:Yt(Vt()),full_size:Yt(Vt()),style_ha_card:Yt(Gt()),style_card_content:Yt(Gt()),disable_dots:Yt(Vt()),entities:Kt({battery:Yt(Gt()),grid:Yt(Gt()),solar:Yt(Gt()),home:Yt(Gt()),fossil_fuel_percentage:Yt(Gt()),individual:Yt(Gt())})})),fi=[{name:"title",label:"Title",selector:{text:{}}}];Qt((e=>[{name:"entities",type:"grid",column_min_width:"400px",schema:[{title:e("editor.grid"),name:"grid",type:"expandable",iconPath:"M8.28,5.45L6.5,4.55L7.76,2H16.23L17.5,4.55L15.72,5.44L15,4H9L8.28,5.45M18.62,8H14.09L13.3,5H10.7L9.91,8H5.38L4.1,10.55L5.89,11.44L6.62,10H17.38L18.1,11.45L19.89,10.56L18.62,8M17.77,22H15.7L15.46,21.1L12,15.9L8.53,21.1L8.3,22H6.23L9.12,11H11.19L10.83,12.35L12,14.1L13.16,12.35L12.81,11H14.88L17.77,22M11.4,15L10.5,13.65L9.32,18.13L11.4,15M14.68,18.12L13.5,13.64L12.6,15L14.68,18.12Z",schema:ii},{title:e("editor.solar"),name:"solar",type:"expandable",iconPath:"M12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7M12,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,2L14.39,5.42C13.65,5.15 12.84,5 12,5C11.16,5 10.35,5.15 9.61,5.42L12,2M3.34,7L7.5,6.65C6.9,7.16 6.36,7.78 5.94,8.5C5.5,9.24 5.25,10 5.11,10.79L3.34,7M3.36,17L5.12,13.23C5.26,14 5.53,14.78 5.95,15.5C6.37,16.24 6.91,16.86 7.5,17.37L3.36,17M20.65,7L18.88,10.79C18.74,10 18.47,9.23 18.05,8.5C17.63,7.78 17.1,7.15 16.5,6.64L20.65,7M20.64,17L16.5,17.36C17.09,16.85 17.62,16.22 18.04,15.5C18.46,14.77 18.73,14 18.87,13.21L20.64,17M12,22L9.59,18.56C10.33,18.83 11.14,19 12,19C12.82,19 13.63,18.83 14.37,18.56L12,22Z",schema:ri},{title:e("editor.battery"),name:"battery",type:"expandable",iconPath:"M16 20H8V6H16M16.67 4H15V2H9V4H7.33C6.6 4 6 4.6 6 5.33V20.67C6 21.4 6.6 22 7.33 22H16.67C17.41 22 18 21.41 18 20.67V5.33C18 4.6 17.4 4 16.67 4M15 16H9V19H15V16M15 7H9V10H15V7M15 11.5H9V14.5H15V11.5Z",schema:ni},{title:e("editor.fossil_fuel_percentage"),name:"fossil_fuel_percentage",type:"expandable",iconPath:"M17,8C8,10 5.9,16.17 3.82,21.34L5.71,22L6.66,19.7C7.14,19.87 7.64,20 8,20C19,20 22,3 22,3C21,5 14,5.25 9,6.25C4,7.25 2,11.5 2,13.5C2,15.5 3.75,17.25 3.75,17.25C7,8 17,8 17,8Z",schema:si},{title:e("editor.home"),name:"home",type:"expandable",iconPath:"M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z",schema:di}]}]));const yi=Qt((e=>[{name:"entities",type:"grid",column_min_width:"400px",schema:[{title:`${e("editor.individual")} 1`,name:"individual1",type:"expandable",schema:li},{title:`${e("editor.individual")} 2`,name:"individual2",type:"expandable",schema:li}]}])),gi=Qt(((e,t)=>[{type:"grid",column_min_width:"200px",schema:[{name:"dashboard_link",label:"Dashboard Link",selector:{navigation:{}}},{name:"dashboard_link_label",label:"Dashboard Link Label",selector:{text:{}}},{name:"w_decimals",label:"Watt Decimals",selector:{number:{mode:"box",min:0,max:5,step:1}}},{name:"kw_decimals",label:"kW Decimals",selector:{number:{mode:"box",min:0,max:5,step:1}}},{name:"max_flow_rate",label:"Max Flow Rate (Sec/Dot)",selector:{number:{mode:"box",min:0,max:1e6,step:.01}}},{name:"min_flow_rate",label:"Min Flow Rate (Sec/Dot)",selector:{number:{mode:"box",min:0,max:1e6,step:.01}}},{name:"max_expected_power",label:"Max Expected Power (in Watts)",selector:{number:{mode:"box",min:0,max:1e6,step:.01}}},{name:"min_expected_power",label:"Min Expected Power (in Watts)",selector:{number:{mode:"box",min:0,max:1e6,step:.01}}},{name:"watt_threshold",label:"Watt to Kilowatt Threshold",selector:{number:{mode:"box",min:0,max:1e6,step:1}}},{name:"clickable_entities",label:"Clickable Entities",selector:{boolean:{}}},{name:"disable_dots",label:"Disable Moving Dots",selector:{boolean:{}}},{name:"use_new_flow_rate_model",label:"New Flow Model?",selector:{boolean:{}}}]},{type:"expandable",title:e("editor.display_zero_lines"),schema:[...vi(e,t)]}])),bi="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,wi=(e,t,o=null)=>{for(;t!==o;){const o=t.nextSibling;e.removeChild(t),t=o}},xi=`{{lit-${String(Math.random()).slice(2)}}}`,ki=`\x3c!--${xi}--\x3e`,Si=new RegExp(`${xi}|${ki}`),$i="$lit$";class Ci{constructor(e,t){this.parts=[],this.element=t;const o=[],i=[],a=document.createTreeWalker(t.content,133,null,!1);let n=0,r=-1,l=0;const{strings:s,values:{length:d}}=e;for(;l0;){const t=s[l],o=Pi.exec(t)[2],i=o.toLowerCase()+$i,a=e.getAttribute(i);e.removeAttribute(i);const n=a.split(Si);this.parts.push({type:"attribute",index:r,name:o,strings:n}),l+=n.length-1}}"TEMPLATE"===e.tagName&&(i.push(e),a.currentNode=e.content)}else if(3===e.nodeType){const t=e.data;if(t.indexOf(xi)>=0){const i=e.parentNode,a=t.split(Si),n=a.length-1;for(let t=0;t{const o=e.length-t.length;return o>=0&&e.slice(o)===t},Ai=e=>-1!==e.index,Mi=()=>document.createComment(""),Pi=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function zi(e,t){const{element:{content:o},parts:i}=e,a=document.createTreeWalker(o,133,null,!1);let n=Ti(i),r=i[n],l=-1,s=0;const d=[];let c=null;for(;a.nextNode();){l++;const e=a.currentNode;for(e.previousSibling===c&&(c=null),t.has(e)&&(d.push(e),null===c&&(c=e)),null!==c&&s++;void 0!==r&&r.index===l;)r.index=null!==c?-1:r.index-s,n=Ti(i,n),r=i[n]}d.forEach((e=>e.parentNode.removeChild(e)))}const Di=e=>{let t=11===e.nodeType?0:1;const o=document.createTreeWalker(e,133,null,!1);for(;o.nextNode();)t++;return t},Ti=(e,t=-1)=>{for(let o=t+1;o"function"==typeof e&&Oi.has(e),ji={},Bi={};class Li{constructor(e,t,o){this.__parts=[],this.template=e,this.processor=t,this.options=o}update(e){let t=0;for(const o of this.__parts)void 0!==o&&o.setValue(e[t]),t++;for(const e of this.__parts)void 0!==e&&e.commit()}_clone(){const e=bi?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),t=[],o=this.template.parts,i=document.createTreeWalker(e,133,null,!1);let a,n=0,r=0,l=i.nextNode();for(;ne}),Hi=` ${xi} `;class Ri{constructor(e,t,o,i){this.strings=e,this.values=t,this.type=o,this.processor=i}getHTML(){const e=this.strings.length-1;let t="",o=!1;for(let i=0;i-1||o)&&-1===e.indexOf("--\x3e",a+1);const n=Pi.exec(e);t+=null===n?e+(o?Hi:ki):e.substr(0,n.index)+n[1]+n[2]+$i+n[3]+xi}return t+=this.strings[e],t}getTemplateElement(){const e=document.createElement("template");let t=this.getHTML();return void 0!==Ii&&(t=Ii.createHTML(t)),e.innerHTML=t,e}}class Fi{constructor(e){this.value=void 0,this.__pendingValue=void 0,this.options=e}appendInto(e){this.startNode=e.appendChild(Mi()),this.endNode=e.appendChild(Mi())}insertAfterNode(e){this.startNode=e,this.endNode=e.nextSibling}appendIntoPart(e){e.__insert(this.startNode=Mi()),e.__insert(this.endNode=Mi())}insertAfterPart(e){e.__insert(this.startNode=Mi()),this.endNode=e.endNode,e.endNode=this.startNode}setValue(e){this.__pendingValue=e}commit(){if(null===this.startNode.parentNode)return;for(;Ni(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=ji,e(this)}const e=this.__pendingValue;e!==ji&&((e=>null===e||!("object"==typeof e||"function"==typeof e))(e)?e!==this.value&&this.__commitText(e):e instanceof Ri?this.__commitTemplateResult(e):e instanceof Node?this.__commitNode(e):(e=>Array.isArray(e)||!(!e||!e[Symbol.iterator]))(e)?this.__commitIterable(e):e===Bi?(this.value=Bi,this.clear()):this.__commitText(e))}__insert(e){this.endNode.parentNode.insertBefore(e,this.endNode)}__commitNode(e){this.value!==e&&(this.clear(),this.__insert(e),this.value=e)}__commitText(e){const t=this.startNode.nextSibling,o="string"==typeof(e=null==e?"":e)?e:String(e);t===this.endNode.previousSibling&&3===t.nodeType?t.data=o:this.__commitNode(document.createTextNode(o)),this.value=e}__commitTemplateResult(e){const t=this.options.templateFactory(e);if(this.value instanceof Li&&this.value.template===t)this.value.update(e.values);else{const o=new Li(t,e.processor,this.options),i=o._clone();o.update(e.values),this.__commitNode(i),this.value=o}}__commitIterable(e){Array.isArray(this.value)||(this.value=[],this.clear());const t=this.value;let o,i=0;for(const a of e)o=t[i],void 0===o&&(o=new Fi(this.options),t.push(o),0===i?o.appendIntoPart(this):o.insertAfterPart(t[i-1])),o.setValue(a),o.commit(),i++;i{try{const e={get capture(){return Ui=!0,!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}})();const Vi=new Map,Wi=new WeakMap;"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.4.1");const Zi=(e,t)=>`${e}--${t}`;let Ki=!0;void 0===window.ShadyCSS?Ki=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),Ki=!1);const Yi=e=>t=>{const o=Zi(t.type,e);let i=Vi.get(o);void 0===i&&(i={stringsArray:new WeakMap,keyString:new Map},Vi.set(o,i));let a=i.stringsArray.get(t.strings);if(void 0!==a)return a;const n=t.strings.join(xi);if(a=i.keyString.get(n),void 0===a){const o=t.getTemplateElement();Ki&&window.ShadyCSS.prepareTemplateDom(o,e),a=new Ci(t,o),i.keyString.set(n,a)}return i.stringsArray.set(t.strings,a),a},Xi=["html","svg"],qi=new Set,Ji=(e,t,o)=>{qi.add(e);const i=o?o.element:document.createElement("template"),a=t.querySelectorAll("style"),{length:n}=a;if(0===n)return void window.ShadyCSS.prepareTemplateStyles(i,e);const r=document.createElement("style");for(let e=0;e{Xi.forEach((t=>{const o=Vi.get(Zi(t,e));void 0!==o&&o.keyString.forEach((e=>{const{element:{content:t}}=e,o=new Set;Array.from(t.querySelectorAll("style")).forEach((e=>{o.add(e)})),zi(e,o)}))}))})(e);const l=i.content;o?function(e,t,o=null){const{element:{content:i},parts:a}=e;if(null==o)return void i.appendChild(t);const n=document.createTreeWalker(i,133,null,!1);let r=Ti(a),l=0,s=-1;for(;n.nextNode();)for(s++,n.currentNode===o&&(l=Di(t),o.parentNode.insertBefore(t,o));-1!==r&&a[r].index===s;){if(l>0){for(;-1!==r;)a[r].index+=l,r=Ti(a,r);return}r=Ti(a,r)}}(o,r,l.firstChild):l.insertBefore(r,l.firstChild),window.ShadyCSS.prepareTemplateStyles(i,e);const s=l.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==s)t.insertBefore(s.cloneNode(!0),t.firstChild);else if(o){l.insertBefore(r,l.firstChild);const e=new Set;e.add(r),zi(o,e)}};window.JSCompiler_renameProperty=(e,t)=>e;const Qi={toAttribute(e,t){switch(t){case Boolean:return e?"":null;case Object:case Array:return null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){switch(t){case Boolean:return null!==e;case Number:return null===e?null:Number(e);case Object:case Array:return JSON.parse(e)}return e}},ea=(e,t)=>t!==e&&(t==t||e==e),ta={attribute:!0,type:String,converter:Qi,reflect:!1,hasChanged:ea},oa="finalized";class ia extends HTMLElement{constructor(){super(),this.initialize()}static get observedAttributes(){this.finalize();const e=[];return this._classProperties.forEach(((t,o)=>{const i=this._attributeNameForProperty(o,t);void 0!==i&&(this._attributeToPropertyMap.set(i,o),e.push(i))})),e}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const e=Object.getPrototypeOf(this)._classProperties;void 0!==e&&e.forEach(((e,t)=>this._classProperties.set(t,e)))}}static createProperty(e,t=ta){if(this._ensureClassProperties(),this._classProperties.set(e,t),t.noAccessor||this.prototype.hasOwnProperty(e))return;const o="symbol"==typeof e?Symbol():`__${e}`,i=this.getPropertyDescriptor(e,o,t);void 0!==i&&Object.defineProperty(this.prototype,e,i)}static getPropertyDescriptor(e,t,o){return{get(){return this[t]},set(i){const a=this[e];this[t]=i,this.requestUpdateInternal(e,a,o)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this._classProperties&&this._classProperties.get(e)||ta}static finalize(){const e=Object.getPrototypeOf(this);if(e.hasOwnProperty(oa)||e.finalize(),this[oa]=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const e=this.properties,t=[...Object.getOwnPropertyNames(e),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e):[]];for(const o of t)this.createProperty(o,e[o])}}static _attributeNameForProperty(e,t){const o=t.attribute;return!1===o?void 0:"string"==typeof o?o:"string"==typeof e?e.toLowerCase():void 0}static _valueHasChanged(e,t,o=ea){return o(e,t)}static _propertyValueFromAttribute(e,t){const o=t.type,i=t.converter||Qi,a="function"==typeof i?i:i.fromAttribute;return a?a(e,o):e}static _propertyValueToAttribute(e,t){if(void 0===t.reflect)return;const o=t.type,i=t.converter;return(i&&i.toAttribute||Qi.toAttribute)(e,o)}initialize(){this._updateState=0,this._updatePromise=new Promise((e=>this._enableUpdatingResolver=e)),this._changedProperties=new Map,this._saveInstanceProperties(),this.requestUpdateInternal()}_saveInstanceProperties(){this.constructor._classProperties.forEach(((e,t)=>{if(this.hasOwnProperty(t)){const e=this[t];delete this[t],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(t,e)}}))}_applyInstanceProperties(){this._instanceProperties.forEach(((e,t)=>this[t]=e)),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(e,t,o){t!==o&&this._attributeToProperty(e,o)}_propertyToAttribute(e,t,o=ta){const i=this.constructor,a=i._attributeNameForProperty(e,o);if(void 0!==a){const e=i._propertyValueToAttribute(t,o);if(void 0===e)return;this._updateState=8|this._updateState,null==e?this.removeAttribute(a):this.setAttribute(a,e),this._updateState=-9&this._updateState}}_attributeToProperty(e,t){if(8&this._updateState)return;const o=this.constructor,i=o._attributeToPropertyMap.get(e);if(void 0!==i){const e=o.getPropertyOptions(i);this._updateState=16|this._updateState,this[i]=o._propertyValueFromAttribute(t,e),this._updateState=-17&this._updateState}}requestUpdateInternal(e,t,o){let i=!0;if(void 0!==e){const a=this.constructor;o=o||a.getPropertyOptions(e),a._valueHasChanged(this[e],t,o.hasChanged)?(this._changedProperties.has(e)||this._changedProperties.set(e,t),!0!==o.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(e,o))):i=!1}!this._hasRequestedUpdate&&i&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(e,t){return this.requestUpdateInternal(e,t),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(e){}const e=this.performUpdate();return null!=e&&await e,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){if(!this._hasRequestedUpdate)return;this._instanceProperties&&this._applyInstanceProperties();let e=!1;const t=this._changedProperties;try{e=this.shouldUpdate(t),e?this.update(t):this._markUpdated()}catch(t){throw e=!1,this._markUpdated(),t}e&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(t)),this.updated(t))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._updatePromise}shouldUpdate(e){return!0}update(e){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach(((e,t)=>this._propertyToAttribute(t,this[t],e))),this._reflectingProperties=void 0),this._markUpdated()}updated(e){}firstUpdated(e){}}ia[oa]=!0;const aa=e=>t=>"function"==typeof t?((e,t)=>(window.customElements.define(e,t),t))(e,t):((e,t)=>{const{kind:o,elements:i}=t;return{kind:o,elements:i,finisher(t){window.customElements.define(e,t)}}})(e,t),na=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?Object.assign(Object.assign({},t),{finisher(o){o.createProperty(t.key,e)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(o){o.createProperty(t.key,e)}},ra=(e,t,o)=>{t.constructor.createProperty(o,e)};function la(e){return(t,o)=>void 0!==o?ra(e,t,o):na(e,t)}const sa=e=>function(e){return la({attribute:!1,hasChanged:null==e?void 0:e.hasChanged})}(e);const da=(e,t,o)=>{Object.defineProperty(t,o,e)},ca=(e,t)=>({kind:"method",placement:"prototype",key:t.key,descriptor:e}),ua=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,ha=Symbol();class pa{constructor(e,t){if(t!==ha)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e}get styleSheet(){return void 0===this._styleSheet&&(ua?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}(window.litElementVersions||(window.litElementVersions=[])).push("2.5.1");const va={};class _a extends ia{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const e=this.getStyles();if(Array.isArray(e)){const t=(e,o)=>e.reduceRight(((e,o)=>Array.isArray(o)?t(o,e):(e.add(o),e)),o),o=t(e,new Set),i=[];o.forEach((e=>i.unshift(e))),this._styles=i}else this._styles=void 0===e?[]:[e];this._styles=this._styles.map((e=>{if(e instanceof CSSStyleSheet&&!ua){const t=Array.prototype.slice.call(e.cssRules).reduce(((e,t)=>e+t.cssText),"");return new pa(String(t),ha)}return e}))}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow(this.constructor.shadowRootOptions)}adoptStyles(){const e=this.constructor._styles;0!==e.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?ua?this.renderRoot.adoptedStyleSheets=e.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(e.map((e=>e.cssText)),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(e){const t=this.render();super.update(e),t!==va&&this.constructor.render(t,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach((e=>{const t=document.createElement("style");t.textContent=e.cssText,this.renderRoot.appendChild(t)})))}render(){return va}}_a.finalized=!0,_a.render=(e,t,o)=>{if(!o||"object"!=typeof o||!o.scopeName)throw new Error("The `scopeName` option is required.");const i=o.scopeName,a=Wi.has(t),n=Ki&&11===t.nodeType&&!!t.host,r=n&&!qi.has(i),l=r?document.createDocumentFragment():t;if(((e,t,o)=>{let i=Wi.get(t);void 0===i&&(wi(t,t.firstChild),Wi.set(t,i=new Fi(Object.assign({templateFactory:Gi},o))),i.appendInto(t)),i.setValue(e),i.commit()})(e,l,Object.assign({templateFactory:Yi(i)},o)),r){const e=Wi.get(l);Wi.delete(l);const o=e.value instanceof Li?e.value.template:void 0;Ji(i,l,o),wi(t,t.firstChild),t.appendChild(l),Wi.set(t,e)}!a&&n&&window.ShadyCSS.styleElement(t.host)},_a.shadowRootOptions={mode:"open"};const{I:ma}=ae,fa=()=>document.createComment(""),ya=(e,t,o)=>{var i;const a=e._$AA.parentNode,n=void 0===t?e._$AB:t._$AA;if(void 0===o){const t=a.insertBefore(fa(),n),i=a.insertBefore(fa(),n);o=new ma(t,i,e,e.options)}else{const t=o._$AB.nextSibling,r=o._$AM,l=r!==e;if(l){let t;null===(i=o._$AQ)||void 0===i||i.call(o,e),o._$AM=e,void 0!==o._$AP&&(t=e._$AU)!==r._$AU&&o._$AP(t)}if(t!==n||l){let e=o._$AA;for(;e!==t;){const t=e.nextSibling;a.insertBefore(e,n),e=t}}}return o},ga=(e,t,o=e)=>(e._$AI(t,o),e),ba={},wa=(e,t=ba)=>e._$AH=t,xa=e=>{var t;null===(t=e._$AP)||void 0===t||t.call(e,!1,!0);let o=e._$AA;const i=e._$AB.nextSibling;for(;o!==i;){const e=o.nextSibling;o.remove(),o=e}},ka=(e,t,o)=>{const i=new Map;for(let a=t;a<=o;a++)i.set(e[a],a);return i},Sa=yt(class extends gt{constructor(e){if(super(e),e.type!==ft)throw Error("repeat() can only be used in text expressions")}ct(e,t,o){let i;void 0===o?o=t:void 0!==t&&(i=t);const a=[],n=[];let r=0;for(const t of e)a[r]=i?i(t,r):r,n[r]=o(t,r),r++;return{values:n,keys:a}}render(e,t,o){return this.ct(e,t,o).values}update(e,[t,o,i]){var a;const n=(e=>e._$AH)(e),{values:r,keys:l}=this.ct(t,o,i);if(!Array.isArray(n))return this.ut=l,r;const s=null!==(a=this.ut)&&void 0!==a?a:this.ut=[],d=[];let c,u,h=0,p=n.length-1,v=0,_=r.length-1;for(;h<=p&&v<=_;)if(null===n[h])h++;else if(null===n[p])p--;else if(s[h]===l[v])d[v]=ga(n[h],r[v]),h++,v++;else if(s[p]===l[_])d[_]=ga(n[p],r[_]),p--,_--;else if(s[h]===l[_])d[_]=ga(n[h],r[_]),ya(e,d[_+1],n[h]),h++,_--;else if(s[p]===l[v])d[v]=ga(n[p],r[v]),ya(e,n[h],n[p]),p--,v++;else if(void 0===c&&(c=ka(l,v,_),u=ka(s,h,p)),c.has(s[h]))if(c.has(s[p])){const t=u.get(l[v]),o=void 0!==t?n[t]:null;if(null===o){const t=ya(e,n[h]);ga(t,r[v]),d[v]=t}else d[v]=ga(o,r[v]),ya(e,n[h],o),n[t]=null;v++}else xa(n[p]),p--;else xa(n[h]),h++;for(;v<=_;){const t=ya(e,d[_+1]);ga(t,r[v]),d[v++]=t}for(;h<=p;){const e=n[h++];null!==e&&xa(e)}return this.ut=l,wa(e,d),F}});let $a;const Ca=(e,t,o,i)=>{i=i||{},o=null==o?{}:o;const a=new Event(t,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return a.detail=o,e.dispatchEvent(a),a},Ea=r`#sortable a:nth-of-type(2n) paper-icon-item{animation-name:keyframes1;animation-iteration-count:infinite;transform-origin:50% 10%;animation-delay:-.75s;animation-duration:.25s}#sortable a:nth-of-type(2n-1) paper-icon-item{animation-name:keyframes2;animation-iteration-count:infinite;animation-direction:alternate;transform-origin:30% 5%;animation-delay:-.5s;animation-duration:.33s}#sortable a{height:48px;display:flex}#sortable{outline:0;display:block!important}.hidden-panel{display:flex!important}.sortable-fallback{display:none}.sortable-ghost{opacity:.4}.sortable-fallback{opacity:0}@keyframes keyframes1{0%{transform:rotate(-1deg);animation-timing-function:ease-in}50%{transform:rotate(1.5deg);animation-timing-function:ease-out}}@keyframes keyframes2{0%{transform:rotate(1deg);animation-timing-function:ease-in}50%{transform:rotate(-1.5deg);animation-timing-function:ease-out}}.hide-panel,.show-panel{display:none;position:absolute;top:0;right:4px;--mdc-icon-button-size:40px}:host([rtl]) .show-panel{right:initial;left:4px}.hide-panel{top:4px;right:8px}:host([rtl]) .hide-panel{right:initial;left:8px}:host([expanded]) .hide-panel{display:block}:host([expanded]) .show-panel{display:inline-flex}paper-icon-item.hidden-panel,paper-icon-item.hidden-panel ha-icon[slot=item-icon],paper-icon-item.hidden-panel span{color:var(--secondary-text-color);cursor:pointer}`,Aa=async()=>{var e,t,o,i;if(customElements.get("ha-form")||null===(e=customElements.get("hui-button-card"))||void 0===e||e.getConfigElement(),customElements.get("ha-entity-picker")||null===(t=customElements.get("hui-entities-card"))||void 0===t||t.getConfigElement(),customElements.get("ha-form"))return;await(null===(i=(o=window).loadCardHelpers)||void 0===i?void 0:i.call(o))};let Ma=class extends se{constructor(){super(...arguments),this._indexBeingEdited=-1,this._entityKeys=new WeakMap,this._computeLabelCallback=e=>this.hass.localize(`ui.panel.lovelace.editor.card.generic.${null==e?void 0:e.name}`)||Yo(`editor.${null==e?void 0:e.name}`)}connectedCallback(){super.connectedCallback(),Aa()}disconnectedCallback(){super.disconnectedCallback(),this._destroySortable()}_editRowElement(e){this._indexBeingEdited=e}_getKey(e){return this._entityKeys.has(e)||this._entityKeys.set(e,Math.random().toString()),this._entityKeys.get(e)}render(){return this.entities&&this.hass?-1!==this._indexBeingEdited?H`

${this._indexBeingEdited+1} / ${this.entities.length} ${Yo("editor.individual")}

`:H`
${Sa(this.entities,(e=>this._getKey(e)),((e,t)=>H`
${e.type?H`
${this.hass.localize(`ui.panel.lovelace.editor.card.entities.entity_row.${e.type}`)} ${this.hass.localize("ui.panel.lovelace.editor.card.entities.edit_special_row")}
`:H``}
`))}
${this.entities.length>=4?U:H``}`:H`

No entities configured.

`}_configChanged(e){const t=e.detail.value||"";if(!this.config||!this.hass)return;Array.isArray(this.config.entities.individual)||(this.config.entities.individual=[]);const o=[...this.config.entities.individual];if(!o)return;o[this._indexBeingEdited]=t;const i=Object.assign(Object.assign({},this.config),{entities:Object.assign(Object.assign({},this.config.entities),{individual:o})});Ca(this,"config-changed",{config:i})}firstUpdated(){this._createSortable()}async _createSortable(){const e=await(async()=>($a||($a=(await Promise.resolve().then((function(){return Ur}))).default),$a))();this._sortable=new e(this.shadowRoot.querySelector(".entities"),{animation:150,fallbackClass:"sortable-fallback",handle:".handle",onChoose:e=>{e.item.placeholder=document.createComment("sort-placeholder"),e.item.after(e.item.placeholder)},onEnd:e=>{e.item.placeholder&&(e.item.placeholder.replaceWith(e.item),delete e.item.placeholder),this._rowMoved(e)}})}_destroySortable(){var e;null===(e=this._sortable)||void 0===e||e.destroy(),this._sortable=void 0}async _addEntity(e){const t=e.detail.value;if(""===t)return;const o=this.entities.concat({entity:t});e.target.value="",Ca(this,"entities-changed",{entities:o})}_rowMoved(e){if(e.oldIndex===e.newIndex)return;const t=this.entities.concat();t.splice(e.newIndex,0,t.splice(e.oldIndex,1)[0]),Ca(this,"entities-changed",{entities:t})}_removeRow(e){const t=e.currentTarget.index,o=this.entities.concat();o.splice(t,1),Ca(this,"entities-changed",{entities:o})}_valueChanged(e){const t=e.detail.value,o=e.target.index,i=this.entities.concat();""===t||void 0===t?i.splice(o,1):i[o]=Object.assign(Object.assign({},i[o]),{entity:t}),Ca(this,"entities-changed",{entities:i})}_editRow(e){const t=e.currentTarget.index;Ca(this,"edit-detail-element",{subElementConfig:{index:t,type:"row",elementConfig:this.entities[t]}})}static get styles(){return[Ea,r`ha-entity-picker{margin-top:8px}.individual-header{display:flex;justify-content:space-between;align-items:center;margin-inline:.2rem;margin-bottom:1rem}.add-entity{display:block;margin-left:31px;margin-right:71px;margin-inline-start:31px;margin-inline-end:71px;direction:var(--direction)}.entity{display:flex;align-items:center}.entity .handle{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}.special-row{height:60px;font-size:16px;display:flex;align-items:center;justify-content:space-between;flex-grow:1}.special-row div{display:flex;flex-direction:column}.edit-icon,.remove-icon{--mdc-icon-button-size:36px;color:var(--secondary-text-color)}.secondary{font-size:12px;color:var(--secondary-text-color)}`]}};e([pe({attribute:!1})],Ma.prototype,"hass",void 0),e([pe({attribute:!1})],Ma.prototype,"config",void 0),e([pe({attribute:!1})],Ma.prototype,"entities",void 0),e([pe()],Ma.prototype,"label",void 0),e([ve()],Ma.prototype,"_indexBeingEdited",void 0),Ma=e([ce("individual-row-editor")],Ma);let Pa=class extends se{constructor(){super(...arguments),this._computeLabelCallback=e=>this.hass.localize(`ui.panel.lovelace.editor.card.generic.${null==e?void 0:e.name}`)||Yo(`editor.${null==e?void 0:e.name}`)}render(){return this.config&&this.hass?(this._configEntities=this.config.entities.individual,this._subElementEditorConfig?H``:H``):H`
no config
`}_valueChanged(e){let t=e.detail.value||"";this.config&&this.hass&&Ae(this,"config-changed",{config:t})}_entitiesChanged(e){let t=this.config;t=Object.assign(Object.assign({},t),{entities:Object.assign(Object.assign({},t.entities),{individual:e.detail.entities})}),this._configEntities=t.entities.individual.map((e=>"string"==typeof e?{entity:e}:e)),Ae(this,"config-changed",{config:t})}_editDetailElement(e){this._subElementEditorConfig=e.detail.subElementConfig}static get styles(){return r``}};e([la({attribute:!1})],Pa.prototype,"config",void 0),e([sa()],Pa.prototype,"_subElementEditorConfig",void 0),e([sa()],Pa.prototype,"_configEntities",void 0),Pa=e([aa("individual-devices-editor")],Pa);let za=class extends se{constructor(){super(...arguments),this.outlined=!1,this.leftChevron=!1,this.icon="mdi:format-list-bulleted-type"}render(){return H``}_focusChanged(e){this.shadowRoot.querySelector(".top").classList.toggle("focused","focus"===e.type)}_openSubElementPage(){Ae(this,"open-sub-element-editor",{open:!0})}static get styles(){return r`:host{display:block}:host([outlined]){box-shadow:none;border-width:1px;border-style:solid;border-color:var(--ha-card-border-color,var(--divider-color,#e0e0e0));border-radius:var(--ha-card-border-radius,12px)}:host([leftchevron]) .summary-icon{margin-left:0;margin-right:8px}.link-subpage{width:100%;display:flex;gap:1rem;padding:var(--expansion-panel-summary-padding,0 8px);min-height:48px;align-items:center;cursor:pointer;overflow:hidden;font-weight:500;outline:0}.summary-icon{transition:transform 150ms cubic-bezier(.4,0,.2,1);direction:var(--direction);color:var(--secondary-text-color)}.header,::slotted([slot=header]){flex:1}.container{padding:var(--expansion-panel-content-padding,0 8px);overflow:hidden;transition:height .3s cubic-bezier(.4,0,.2,1);height:0}.container.expanded{height:auto}.secondary{display:block;color:var(--secondary-text-color);font-size:12px}`}};var Da,Ta;e([la({type:String})],za.prototype,"path",void 0),e([la({type:Boolean,reflect:!0})],za.prototype,"outlined",void 0),e([la({type:Boolean,reflect:!0})],za.prototype,"leftChevron",void 0),e([la()],za.prototype,"header",void 0),e([la({type:String})],za.prototype,"icon",void 0),e([la()],za.prototype,"secondary",void 0),e([(Da=".container",(e,t)=>{const o={get(){return this.renderRoot.querySelector(Da)},enumerable:!0,configurable:!0};if(Ta){const i=void 0!==t?t:e.key,a="symbol"==typeof i?Symbol():`__${i}`;o.get=function(){return void 0===this[a]&&(this[a]=this.renderRoot.querySelector(Da)),this[a]}}return void 0!==t?da(o,e,t):ca(o,e)})],za.prototype,"_container",void 0),za=e([aa("link-subpage")],za);let Oa=class extends se{render(){return H`
${Yo(`editor.${this.page}`)}
`}_goBack(){Ae(this,"go-back")}static get styles(){return r`.header{display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem}.back-title{display:flex;align-items:center;font-size:18px}`}};e([la({attribute:!1})],Oa.prototype,"config",void 0),e([la()],Oa.prototype,"page",void 0),Oa=e([aa("subpage-header")],Oa);const Na=[{page:"grid",icon:"mdi:transmission-tower",schema:ii},{page:"solar",icon:"mdi:solar-power",schema:ri},{page:"battery",icon:"mdi:battery-high",schema:ni},{page:"fossil_fuel_percentage",icon:"mdi:leaf",schema:si},{page:"home",icon:"mdi:home",schema:di},{page:"individual",icon:"mdi:dots-horizontal-circle-outline"},{page:"advanced",icon:"mdi:cog",schema:gi}];let ja=class extends se{constructor(){super(...arguments),this._configEntities=[],this._currentConfigPage=null,this._computeLabelCallback=e=>this.hass.localize(`ui.panel.lovelace.editor.card.generic.${null==e?void 0:e.name}`)||Yo(`editor.${null==e?void 0:e.name}`)}async setConfig(e){Rt(e,mi),this._config=e}connectedCallback(){super.connectedCallback(),Aa()}_editDetailElement(e){this._currentConfigPage=e}_goBack(){this._currentConfigPage=null}render(){var e,t,o,i,a,n,r,l,s;if(!this.hass||!this._config)return U;const d=Object.assign(Object.assign({},this._config),{display_zero_lines:{mode:null!==(t=null===(e=this._config.display_zero_lines)||void 0===e?void 0:e.mode)&&void 0!==t?t:we.displayZeroLines.mode,transparency:null!==(i=null===(o=this._config.display_zero_lines)||void 0===o?void 0:o.transparency)&&void 0!==i?i:we.displayZeroLines.transparency,grey_color:null!==(n=null===(a=this._config.display_zero_lines)||void 0===a?void 0:a.grey_color)&&void 0!==n?n:we.displayZeroLines.grey_color}});if(null!==this._currentConfigPage){if("individual"===this._currentConfigPage)return H``;const e=this._currentConfigPage,t="advanced"===e?gi(Yo,null!==(l=null===(r=this._config.display_zero_lines)||void 0===r?void 0:r.mode)&&void 0!==l?l:we.displayZeroLines.mode):null===(s=Na.find((t=>t.page===e)))||void 0===s?void 0:s.schema,o="advanced"===e?d:d.entities[e];return H``}const c=(e,t="mdi:dots-horizontal-circle-outline")=>{if(null===e)return H``;const o=(()=>{var o,i;return"individual"===e||"advanced"===e?t:(null===(i=null===(o=null==this?void 0:this._config)||void 0===o?void 0:o.entities[e])||void 0===i?void 0:i.icon)||t})();return H``};return H`
${Na.map((e=>c(e.page,e.icon)))}
`}_valueChanged(e){let t=e.detail.value||"";this._config&&this.hass&&(null!==this._currentConfigPage&&"advanced"!==this._currentConfigPage&&"individual"!==this._currentConfigPage&&(t=Object.assign(Object.assign({},this._config),{entities:Object.assign(Object.assign({},this._config.entities),{[this._currentConfigPage]:t})})),Ae(this,"config-changed",{config:t}))}static get styles(){return r`ha-form{width:100%}ha-icon-button{align-self:center}.entities-section *{background-color:red}.card-config{display:flex;flex-direction:column;gap:1.5rem;margin-bottom:10px}.config-header{display:flex;flex-direction:row;justify-content:space-between;align-items:center;width:100%}.config-header.sub-header{margin-top:24px}ha-icon{padding-bottom:2px;position:relative;top:-4px;right:1px}`}};e([pe({attribute:!1})],ja.prototype,"hass",void 0),e([ve()],ja.prototype,"_config",void 0),e([ve()],ja.prototype,"_configEntities",void 0),e([ve()],ja.prototype,"_currentConfigPage",void 0),ja=e([ce("power-flow-card-plus-editor")],ja);var Ba=Object.freeze({__proto__:null,get PowerFlowCardPlusEditor(){return ja}});function La(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,i)}return o}function Ia(e){for(var t=1;t=0||(a[o]=e[o]);return a}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(a[o]=e[o])}return a}function Ga(e){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(e)}var Va=Ga(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Wa=Ga(/Edge/i),Za=Ga(/firefox/i),Ka=Ga(/safari/i)&&!Ga(/chrome/i)&&!Ga(/android/i),Ya=Ga(/iP(ad|od|hone)/i),Xa=Ga(/chrome/i)&&Ga(/android/i),qa={capture:!1,passive:!1};function Ja(e,t,o){e.addEventListener(t,o,!Va&&qa)}function Qa(e,t,o){e.removeEventListener(t,o,!Va&&qa)}function en(e,t){if(t){if(">"===t[0]&&(t=t.substring(1)),e)try{if(e.matches)return e.matches(t);if(e.msMatchesSelector)return e.msMatchesSelector(t);if(e.webkitMatchesSelector)return e.webkitMatchesSelector(t)}catch(e){return!1}return!1}}function tn(e){return e.host&&e!==document&&e.host.nodeType?e.host:e.parentNode}function on(e,t,o,i){if(e){o=o||document;do{if(null!=t&&(">"===t[0]?e.parentNode===o&&en(e,t):en(e,t))||i&&e===o)return e;if(e===o)break}while(e=tn(e))}return null}var an,nn=/\s+/g;function rn(e,t,o){if(e&&t)if(e.classList)e.classList[o?"add":"remove"](t);else{var i=(" "+e.className+" ").replace(nn," ").replace(" "+t+" "," ");e.className=(i+(o?" "+t:"")).replace(nn," ")}}function ln(e,t,o){var i=e&&e.style;if(i){if(void 0===o)return document.defaultView&&document.defaultView.getComputedStyle?o=document.defaultView.getComputedStyle(e,""):e.currentStyle&&(o=e.currentStyle),void 0===t?o:o[t];t in i||-1!==t.indexOf("webkit")||(t="-webkit-"+t),i[t]=o+("string"==typeof o?"":"px")}}function sn(e,t){var o="";if("string"==typeof e)o=e;else do{var i=ln(e,"transform");i&&"none"!==i&&(o=i+" "+o)}while(!t&&(e=e.parentNode));var a=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return a&&new a(o)}function dn(e,t,o){if(e){var i=e.getElementsByTagName(t),a=0,n=i.length;if(o)for(;a=n:a<=n))return i;if(i===cn())break;i=fn(i,!1)}return!1}function pn(e,t,o,i){for(var a=0,n=0,r=e.children;n2&&void 0!==arguments[2]?arguments[2]:{},i=o.evt,a=Ua(o,An);En.pluginEvent.bind(wr)(e,t,Ia({dragEl:zn,parentEl:Dn,ghostEl:Tn,rootEl:On,nextEl:Nn,lastDownEl:jn,cloneEl:Bn,cloneHidden:Ln,dragStarted:qn,putSortable:Gn,activeSortable:wr.active,originalEvent:i,oldIndex:In,oldDraggableIndex:Rn,newIndex:Hn,newDraggableIndex:Fn,hideGhostForTarget:fr,unhideGhostForTarget:yr,cloneNowHidden:function(){Ln=!0},cloneNowShown:function(){Ln=!1},dispatchSortableEvent:function(e){Pn({sortable:t,name:e,originalEvent:i})}},a))};function Pn(e){!function(e){var t=e.sortable,o=e.rootEl,i=e.name,a=e.targetEl,n=e.cloneEl,r=e.toEl,l=e.fromEl,s=e.oldIndex,d=e.newIndex,c=e.oldDraggableIndex,u=e.newDraggableIndex,h=e.originalEvent,p=e.putSortable,v=e.extraEventProperties;if(t=t||o&&o[kn]){var _,m=t.options,f="on"+i.charAt(0).toUpperCase()+i.substr(1);!window.CustomEvent||Va||Wa?(_=document.createEvent("Event")).initEvent(i,!0,!0):_=new CustomEvent(i,{bubbles:!0,cancelable:!0}),_.to=r||o,_.from=l||o,_.item=a||o,_.clone=n,_.oldIndex=s,_.newIndex=d,_.oldDraggableIndex=c,_.newDraggableIndex=u,_.originalEvent=h,_.pullMode=p?p.lastPutMode:void 0;var y=Ia(Ia({},v),En.getEventProperties(i,t));for(var g in y)_[g]=y[g];o&&o.dispatchEvent(_),m[f]&&m[f].call(t,_)}}(Ia({putSortable:Gn,cloneEl:Bn,targetEl:zn,rootEl:On,oldIndex:In,oldDraggableIndex:Rn,newIndex:Hn,newDraggableIndex:Fn},e))}var zn,Dn,Tn,On,Nn,jn,Bn,Ln,In,Hn,Rn,Fn,Un,Gn,Vn,Wn,Zn,Kn,Yn,Xn,qn,Jn,Qn,er,tr,or=!1,ir=!1,ar=[],nr=!1,rr=!1,lr=[],sr=!1,dr=[],cr="undefined"!=typeof document,ur=Ya,hr=Wa||Va?"cssFloat":"float",pr=cr&&!Xa&&!Ya&&"draggable"in document.createElement("div"),vr=function(){if(cr){if(Va)return!1;var e=document.createElement("x");return e.style.cssText="pointer-events:auto","auto"===e.style.pointerEvents}}(),_r=function(e,t){var o=ln(e),i=parseInt(o.width)-parseInt(o.paddingLeft)-parseInt(o.paddingRight)-parseInt(o.borderLeftWidth)-parseInt(o.borderRightWidth),a=pn(e,0,t),n=pn(e,1,t),r=a&&ln(a),l=n&&ln(n),s=r&&parseInt(r.marginLeft)+parseInt(r.marginRight)+un(a).width,d=l&&parseInt(l.marginLeft)+parseInt(l.marginRight)+un(n).width;if("flex"===o.display)return"column"===o.flexDirection||"column-reverse"===o.flexDirection?"vertical":"horizontal";if("grid"===o.display)return o.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(a&&r.float&&"none"!==r.float){var c="left"===r.float?"left":"right";return!n||"both"!==l.clear&&l.clear!==c?"horizontal":"vertical"}return a&&("block"===r.display||"flex"===r.display||"table"===r.display||"grid"===r.display||s>=i&&"none"===o[hr]||n&&"none"===o[hr]&&s+d>i)?"vertical":"horizontal"},mr=function(e){function t(e,o){return function(i,a,n,r){var l=i.options.group.name&&a.options.group.name&&i.options.group.name===a.options.group.name;if(null==e&&(o||l))return!0;if(null==e||!1===e)return!1;if(o&&"clone"===e)return e;if("function"==typeof e)return t(e(i,a,n,r),o)(i,a,n,r);var s=(o?i:a).options.group.name;return!0===e||"string"==typeof e&&e===s||e.join&&e.indexOf(s)>-1}}var o={},i=e.group;i&&"object"==Ha(i)||(i={name:i}),o.name=i.name,o.checkPull=t(i.pull,!0),o.checkPut=t(i.put),o.revertClone=i.revertClone,e.group=o},fr=function(){!vr&&Tn&&ln(Tn,"display","none")},yr=function(){!vr&&Tn&&ln(Tn,"display","")};cr&&!Xa&&document.addEventListener("click",(function(e){if(ir)return e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),ir=!1,!1}),!0);var gr=function(e){if(zn){var t=function(e,t){var o;return ar.some((function(i){var a=i[kn].options.emptyInsertThreshold;if(a&&!vn(i)){var n=un(i),r=e>=n.left-a&&e<=n.right+a,l=t>=n.top-a&&t<=n.bottom+a;return r&&l?o=i:void 0}})),o}((e=e.touches?e.touches[0]:e).clientX,e.clientY);if(t){var o={};for(var i in e)e.hasOwnProperty(i)&&(o[i]=e[i]);o.target=o.rootEl=t,o.preventDefault=void 0,o.stopPropagation=void 0,t[kn]._onDragOver(o)}}},br=function(e){zn&&zn.parentNode[kn]._isOutsideThisEl(e.target)};function wr(e,t){if(!e||!e.nodeType||1!==e.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(e));this.el=e,this.options=t=Fa({},t),e[kn]=this;var o={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(e.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return _r(e,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(e,t){e.setData("Text",t.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==wr.supportPointer&&"PointerEvent"in window&&!Ka,emptyInsertThreshold:5};for(var i in En.initializePlugins(this,e,o),o)!(i in t)&&(t[i]=o[i]);for(var a in mr(t),this)"_"===a.charAt(0)&&"function"==typeof this[a]&&(this[a]=this[a].bind(this));this.nativeDraggable=!t.forceFallback&&pr,this.nativeDraggable&&(this.options.touchStartThreshold=1),t.supportPointer?Ja(e,"pointerdown",this._onTapStart):(Ja(e,"mousedown",this._onTapStart),Ja(e,"touchstart",this._onTapStart)),this.nativeDraggable&&(Ja(e,"dragover",this),Ja(e,"dragenter",this)),ar.push(this.el),t.store&&t.store.get&&this.sort(t.store.get(this)||[]),Fa(this,Sn())}function xr(e,t,o,i,a,n,r,l){var s,d,c=e[kn],u=c.options.onMove;return!window.CustomEvent||Va||Wa?(s=document.createEvent("Event")).initEvent("move",!0,!0):s=new CustomEvent("move",{bubbles:!0,cancelable:!0}),s.to=t,s.from=e,s.dragged=o,s.draggedRect=i,s.related=a||t,s.relatedRect=n||un(t),s.willInsertAfter=l,s.originalEvent=r,e.dispatchEvent(s),u&&(d=u.call(c,s,r)),d}function kr(e){e.draggable=!1}function Sr(){sr=!1}function $r(e){for(var t=e.tagName+e.className+e.src+e.href+e.textContent,o=t.length,i=0;o--;)i+=t.charCodeAt(o);return i.toString(36)}function Cr(e){return setTimeout(e,0)}function Er(e){return clearTimeout(e)}wr.prototype={constructor:wr,_isOutsideThisEl:function(e){this.el.contains(e)||e===this.el||(Jn=null)},_getDirection:function(e,t){return"function"==typeof this.options.direction?this.options.direction.call(this,e,t,zn):this.options.direction},_onTapStart:function(e){if(e.cancelable){var t=this,o=this.el,i=this.options,a=i.preventOnFilter,n=e.type,r=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,l=(r||e).target,s=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||l,d=i.filter;if(function(e){dr.length=0;var t=e.getElementsByTagName("input"),o=t.length;for(;o--;){var i=t[o];i.checked&&dr.push(i)}}(o),!zn&&!(/mousedown|pointerdown/.test(n)&&0!==e.button||i.disabled)&&!s.isContentEditable&&(this.nativeDraggable||!Ka||!l||"SELECT"!==l.tagName.toUpperCase())&&!((l=on(l,i.draggable,o,!1))&&l.animated||jn===l)){if(In=_n(l),Rn=_n(l,i.draggable),"function"==typeof d){if(d.call(this,e,l,this))return Pn({sortable:t,rootEl:s,name:"filter",targetEl:l,toEl:o,fromEl:o}),Mn("filter",t,{evt:e}),void(a&&e.cancelable&&e.preventDefault())}else if(d&&(d=d.split(",").some((function(i){if(i=on(s,i.trim(),o,!1))return Pn({sortable:t,rootEl:i,name:"filter",targetEl:l,fromEl:o,toEl:o}),Mn("filter",t,{evt:e}),!0}))))return void(a&&e.cancelable&&e.preventDefault());i.handle&&!on(s,i.handle,o,!1)||this._prepareDragStart(e,r,l)}}},_prepareDragStart:function(e,t,o){var i,a=this,n=a.el,r=a.options,l=n.ownerDocument;if(o&&!zn&&o.parentNode===n){var s=un(o);if(On=n,Dn=(zn=o).parentNode,Nn=zn.nextSibling,jn=o,Un=r.group,wr.dragged=zn,Vn={target:zn,clientX:(t||e).clientX,clientY:(t||e).clientY},Yn=Vn.clientX-s.left,Xn=Vn.clientY-s.top,this._lastX=(t||e).clientX,this._lastY=(t||e).clientY,zn.style["will-change"]="all",i=function(){Mn("delayEnded",a,{evt:e}),wr.eventCanceled?a._onDrop():(a._disableDelayedDragEvents(),!Za&&a.nativeDraggable&&(zn.draggable=!0),a._triggerDragStart(e,t),Pn({sortable:a,name:"choose",originalEvent:e}),rn(zn,r.chosenClass,!0))},r.ignore.split(",").forEach((function(e){dn(zn,e.trim(),kr)})),Ja(l,"dragover",gr),Ja(l,"mousemove",gr),Ja(l,"touchmove",gr),Ja(l,"mouseup",a._onDrop),Ja(l,"touchend",a._onDrop),Ja(l,"touchcancel",a._onDrop),Za&&this.nativeDraggable&&(this.options.touchStartThreshold=4,zn.draggable=!0),Mn("delayStart",this,{evt:e}),!r.delay||r.delayOnTouchOnly&&!t||this.nativeDraggable&&(Wa||Va))i();else{if(wr.eventCanceled)return void this._onDrop();Ja(l,"mouseup",a._disableDelayedDrag),Ja(l,"touchend",a._disableDelayedDrag),Ja(l,"touchcancel",a._disableDelayedDrag),Ja(l,"mousemove",a._delayedDragTouchMoveHandler),Ja(l,"touchmove",a._delayedDragTouchMoveHandler),r.supportPointer&&Ja(l,"pointermove",a._delayedDragTouchMoveHandler),a._dragStartTimer=setTimeout(i,r.delay)}}},_delayedDragTouchMoveHandler:function(e){var t=e.touches?e.touches[0]:e;Math.max(Math.abs(t.clientX-this._lastX),Math.abs(t.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){zn&&kr(zn),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;Qa(e,"mouseup",this._disableDelayedDrag),Qa(e,"touchend",this._disableDelayedDrag),Qa(e,"touchcancel",this._disableDelayedDrag),Qa(e,"mousemove",this._delayedDragTouchMoveHandler),Qa(e,"touchmove",this._delayedDragTouchMoveHandler),Qa(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,t){t=t||"touch"==e.pointerType&&e,!this.nativeDraggable||t?this.options.supportPointer?Ja(document,"pointermove",this._onTouchMove):Ja(document,t?"touchmove":"mousemove",this._onTouchMove):(Ja(zn,"dragend",this),Ja(On,"dragstart",this._onDragStart));try{document.selection?Cr((function(){document.selection.empty()})):window.getSelection().removeAllRanges()}catch(e){}},_dragStarted:function(e,t){if(or=!1,On&&zn){Mn("dragStarted",this,{evt:t}),this.nativeDraggable&&Ja(document,"dragover",br);var o=this.options;!e&&rn(zn,o.dragClass,!1),rn(zn,o.ghostClass,!0),wr.active=this,e&&this._appendGhost(),Pn({sortable:this,name:"start",originalEvent:t})}else this._nulling()},_emulateDragOver:function(){if(Wn){this._lastX=Wn.clientX,this._lastY=Wn.clientY,fr();for(var e=document.elementFromPoint(Wn.clientX,Wn.clientY),t=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(Wn.clientX,Wn.clientY))!==t;)t=e;if(zn.parentNode[kn]._isOutsideThisEl(e),t)do{if(t[kn]){if(t[kn]._onDragOver({clientX:Wn.clientX,clientY:Wn.clientY,target:e,rootEl:t})&&!this.options.dragoverBubble)break}e=t}while(t=t.parentNode);yr()}},_onTouchMove:function(e){if(Vn){var t=this.options,o=t.fallbackTolerance,i=t.fallbackOffset,a=e.touches?e.touches[0]:e,n=Tn&&sn(Tn,!0),r=Tn&&n&&n.a,l=Tn&&n&&n.d,s=ur&&tr&&mn(tr),d=(a.clientX-Vn.clientX+i.x)/(r||1)+(s?s[0]-lr[0]:0)/(r||1),c=(a.clientY-Vn.clientY+i.y)/(l||1)+(s?s[1]-lr[1]:0)/(l||1);if(!wr.active&&!or){if(o&&Math.max(Math.abs(a.clientX-this._lastX),Math.abs(a.clientY-this._lastY))a.right+n||e.clientY>i.bottom&&e.clientX>i.left:e.clientY>a.bottom+n||e.clientX>i.right&&e.clientY>i.top}(e,a,this)&&!_.animated){if(_===zn)return z(!1);if(_&&n===e.target&&(r=_),r&&(o=un(r)),!1!==xr(On,n,zn,t,r,o,e,!!r))return P(),_&&_.nextSibling?n.insertBefore(zn,_.nextSibling):n.appendChild(zn),Dn=n,D(),z(!0)}else if(_&&function(e,t,o){var i=un(pn(o.el,0,o.options,!0)),a=xn(o.el,o.options,Tn),n=10;return t?e.clientXc+d*n/2:su-er)return-Qn}else if(s>c+d*(1-a)/2&&su-d*n/2))return s>c+d/2?1:-1;return 0}(e,r,o,a,w?1:l.swapThreshold,null==l.invertedSwapThreshold?l.swapThreshold:l.invertedSwapThreshold,rr,Jn===r),0!==f){var $=_n(zn);do{$-=f,g=Dn.children[$]}while(g&&("none"===ln(g,"display")||g===Tn))}if(0===f||g===r)return z(!1);Jn=r,Qn=f;var C=r.nextElementSibling,E=!1,A=xr(On,n,zn,t,r,o,e,E=1===f);if(!1!==A)return 1!==A&&-1!==A||(E=1===A),sr=!0,setTimeout(Sr,30),P(),E&&!C?n.appendChild(zn):r.parentNode.insertBefore(zn,E?C:r),k&&bn(k,0,S-k.scrollTop),Dn=zn.parentNode,void 0===y||rr||(er=Math.abs(y-un(r)[x])),D(),z(!0)}if(n.contains(zn))return z(!1)}return!1}function M(l,s){Mn(l,p,Ia({evt:e,isOwner:c,axis:a?"vertical":"horizontal",revert:i,dragRect:t,targetRect:o,canSort:u,fromSortable:h,target:r,completed:z,onMove:function(o,i){return xr(On,n,zn,t,o,un(o),e,i)},changed:D},s))}function P(){M("dragOverAnimationCapture"),p.captureAnimationState(),p!==h&&h.captureAnimationState()}function z(t){return M("dragOverCompleted",{insertion:t}),t&&(c?d._hideClone():d._showClone(p),p!==h&&(rn(zn,Gn?Gn.options.ghostClass:d.options.ghostClass,!1),rn(zn,l.ghostClass,!0)),Gn!==p&&p!==wr.active?Gn=p:p===wr.active&&Gn&&(Gn=null),h===p&&(p._ignoreWhileAnimating=r),p.animateAll((function(){M("dragOverAnimationComplete"),p._ignoreWhileAnimating=null})),p!==h&&(h.animateAll(),h._ignoreWhileAnimating=null)),(r===zn&&!zn.animated||r===n&&!r.animated)&&(Jn=null),l.dragoverBubble||e.rootEl||r===document||(zn.parentNode[kn]._isOutsideThisEl(e.target),!t&&gr(e)),!l.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),v=!0}function D(){Hn=_n(zn),Fn=_n(zn,l.draggable),Pn({sortable:p,name:"change",toEl:n,newIndex:Hn,newDraggableIndex:Fn,originalEvent:e})}},_ignoreWhileAnimating:null,_offMoveEvents:function(){Qa(document,"mousemove",this._onTouchMove),Qa(document,"touchmove",this._onTouchMove),Qa(document,"pointermove",this._onTouchMove),Qa(document,"dragover",gr),Qa(document,"mousemove",gr),Qa(document,"touchmove",gr)},_offUpEvents:function(){var e=this.el.ownerDocument;Qa(e,"mouseup",this._onDrop),Qa(e,"touchend",this._onDrop),Qa(e,"pointerup",this._onDrop),Qa(e,"touchcancel",this._onDrop),Qa(document,"selectstart",this)},_onDrop:function(e){var t=this.el,o=this.options;Hn=_n(zn),Fn=_n(zn,o.draggable),Mn("drop",this,{evt:e}),Dn=zn&&zn.parentNode,Hn=_n(zn),Fn=_n(zn,o.draggable),wr.eventCanceled||(or=!1,rr=!1,nr=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),Er(this.cloneId),Er(this._dragStartId),this.nativeDraggable&&(Qa(document,"drop",this),Qa(t,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),Ka&&ln(document.body,"user-select",""),ln(zn,"transform",""),e&&(qn&&(e.cancelable&&e.preventDefault(),!o.dropBubble&&e.stopPropagation()),Tn&&Tn.parentNode&&Tn.parentNode.removeChild(Tn),(On===Dn||Gn&&"clone"!==Gn.lastPutMode)&&Bn&&Bn.parentNode&&Bn.parentNode.removeChild(Bn),zn&&(this.nativeDraggable&&Qa(zn,"dragend",this),kr(zn),zn.style["will-change"]="",qn&&!or&&rn(zn,Gn?Gn.options.ghostClass:this.options.ghostClass,!1),rn(zn,this.options.chosenClass,!1),Pn({sortable:this,name:"unchoose",toEl:Dn,newIndex:null,newDraggableIndex:null,originalEvent:e}),On!==Dn?(Hn>=0&&(Pn({rootEl:Dn,name:"add",toEl:Dn,fromEl:On,originalEvent:e}),Pn({sortable:this,name:"remove",toEl:Dn,originalEvent:e}),Pn({rootEl:Dn,name:"sort",toEl:Dn,fromEl:On,originalEvent:e}),Pn({sortable:this,name:"sort",toEl:Dn,originalEvent:e})),Gn&&Gn.save()):Hn!==In&&Hn>=0&&(Pn({sortable:this,name:"update",toEl:Dn,originalEvent:e}),Pn({sortable:this,name:"sort",toEl:Dn,originalEvent:e})),wr.active&&(null!=Hn&&-1!==Hn||(Hn=In,Fn=Rn),Pn({sortable:this,name:"end",toEl:Dn,originalEvent:e}),this.save())))),this._nulling()},_nulling:function(){Mn("nulling",this),On=zn=Dn=Tn=Nn=Bn=jn=Ln=Vn=Wn=qn=Hn=Fn=In=Rn=Jn=Qn=Gn=Un=wr.dragged=wr.ghost=wr.clone=wr.active=null,dr.forEach((function(e){e.checked=!0})),dr.length=Zn=Kn=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":zn&&(this._onDragOver(e),function(e){e.dataTransfer&&(e.dataTransfer.dropEffect="move");e.cancelable&&e.preventDefault()}(e));break;case"selectstart":e.preventDefault()}},toArray:function(){for(var e,t=[],o=this.el.children,i=0,a=o.length,n=this.options;i