export const __rspack_esm_id="25500";export const __rspack_esm_ids=["25500"];export const __webpack_modules__={62743(t,a,e){e.a(t,async function(t,s){try{e.r(a),e.d(a,{HuiEnergyWaterGraphCard:()=>k});e(44114),e(18111),e(22489),e(7588),e(18237);var r=e(62826),i=e(73684),o=e(40600),n=e(81859),h=e(96196),c=e(44457),_=e(94333),p=e(22786),d=e(18427),l=e(44439),g=(e(76776),e(38114)),u=e(23528),y=e(54706),m=e(784),f=e(97372),b=e(20058),v=e(40345),w=e(34127),C=t([l,v,w,g,b,f]);[l,v,w,g,b,f]=C.then?(await C)():C;class k extends((0,y.E)(h.WF)){hassSubscribe(){return[(0,g.tb)(this.hass,{key:this._config?.collection_key}).subscribe(t=>this._getStatistics(t))]}getCardSize(){return 3}setConfig(t){this._config=t}shouldUpdate(t){return(0,m.xP)(this,t)||t.size>1||!t.has("hass")}render(){return this.hass&&this._config?h.qy` <ha-card> ${this._config.title?h.qy` <div class="card-header"> <span>${this._config.title?this._config.title:h.s6}</span> ${this._total?h.qy`<hui-energy-graph-chip .tooltip="${this._formatTotal(this._total)}"> ${(0,b.ZV)(this._total,this.hass.locale)} ${this._unit} </hui-energy-graph-chip>`:h.s6} </div>`:h.s6} <div class="content ${(0,_.H)({"has-header":!!this._config.title})}"> <ha-chart-base .hass="${this.hass}" .data="${this._chartData}" .options="${this._createOptions(this._start,this._end,this.hass.locale,this.hass.config,this._unit,this._compareStart,this._compareEnd)}" chart-type="bar"></ha-chart-base> ${this._chartData.length?"":h.qy`<div class="no-data"> ${(0,i.c)(this._start)?this.hass.localize("ui.panel.lovelace.cards.energy.no_data"):this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period")} </div>`} </div> </ha-card> `:h.s6}async _getStatistics(t){this._start=t.start,this._end=t.end||(0,o.o)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const a=t.prefs.energy_sources.filter(t=>"water"===t.type);this._unit=t.waterUnit;const e=[],s=getComputedStyle(this);if(t.statsCompare)e.push(...this._processDataSet(t.statsCompare,t.statsMetadata,a,s,!0));else{const t=a[0]?.stat_energy_from??"placeholder";e.push({id:"compare-"+t,type:"bar",stack:"water",data:[]})}e.push(...this._processDataSet(t.stats,t.statsMetadata,a,s)),(0,f.RR)(e),this._chartData=e,this._total=this._processTotal(t.stats,a)}_processTotal(t,a){return a.reduce((a,e)=>a+(e.stat_energy_from in t?t[e.stat_energy_from].reduce((t,a)=>t+(a.change||0),0):0),0)}_processDataSet(t,a,e,s,r=!1){const i=[],o=(0,f.ok)(this._start,this._compareStart);return e.forEach((e,n)=>{let h=null;const c=[];if(e.stat_energy_from in t){const a=t[e.stat_energy_from];for(const t of a){if(null===t.change||void 0===t.change||0===t.change)continue;if(h===t.start)continue;const a=[t.start,t.change];r&&(a[2]=a[0],a[0]=o(new Date(t.start))),c.push(a),h=t.start}}i.push({type:"bar",cursor:"default",id:r?"compare-"+e.stat_energy_from:e.stat_energy_from,name:(0,u.$O)(this.hass,e.stat_energy_from,a[e.stat_energy_from]),barMaxWidth:50,itemStyle:{borderColor:(0,d.g)(s,this.hass.themes.darkMode,!1,r,"--energy-water-color",n)},color:(0,d.g)(s,this.hass.themes.darkMode,!0,r,"--energy-water-color",n),data:c,stack:r?"compare":"water"})}),i}constructor(...t){super(...t),this._chartData=[],this._start=(0,n.R)(),this._end=(0,o.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._formatTotal=t=>this.hass.localize("ui.panel.lovelace.cards.energy.energy_water_graph.total_consumed",{num:(0,b.ZV)(t,this.hass.locale),unit:this._unit}),this._createOptions=(0,p.A)((t,a,e,s,r,i,o)=>(0,f.od)(t,a,e,s,r,i,o,this._formatTotal))}}k.styles=h.AH`ha-card{height:100%}.card-header{display:flex;justify-content:space-between;align-items:center;padding-bottom:0}.content{padding:16px}.has-header{padding-top:0}.no-data{position:absolute;height:100%;top:0;left:0;right:0;display:flex;justify-content:center;align-items:center;padding:20%;margin-left:32px;margin-inline-start:32px;margin-inline-end:initial;box-sizing:border-box}`,(0,r.Cg)([(0,c.MZ)({attribute:!1})],k.prototype,"hass",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_config",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_chartData",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_start",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_end",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_compareStart",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_compareEnd",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_unit",void 0),(0,r.Cg)([(0,c.wk)()],k.prototype,"_total",void 0),k=(0,r.Cg)([(0,c.EM)("hui-energy-water-graph-card")],k),s()}catch(t){s(t)}})}};
//# sourceMappingURL=25500.f4a2b6d570e10ab8.js.map