export const __rspack_esm_id=89954;export const __rspack_esm_ids=[89954];export const __webpack_modules__={94809(t,i,s){s.a(t,async function(t,o){try{s.r(i);s(74423),s(18111),s(22489);var e=s(15697),r=s(57527),n=s(79224),h=s(98295),a=s(148),c=s(45602),_=s(88457),d=s(87581),l=s(98357),u=s(61844),g=(s(18581),t([_,d]));[_,d]=g.then?(await g)():g;const f=6e4,y=60*f,b=["counter","input_number","number","sensor"];class p extends r.WF{static async getConfigElement(){return await Promise.all([s.e(55616),s.e(38222)]).then(s.bind(s,7882)),document.createElement("hui-graph-footer-editor")}static getStubConfig(t,i,s){return{type:"graph",entity:(0,l.B)(t,1,i,s,b,t=>!isNaN(Number(t.state))&&!!t.attributes.unit_of_measurement)[0]||""}}getCardSize(){return 3}setConfig(t){if(!t?.entity||!b.includes((0,c.m)(t.entity)))throw new Error("Specify an entity from within the sensor domain");const i={detail:1,hours_to_show:24,...t};i.hours_to_show=Number(i.hours_to_show),i.detail=1===i.detail||2===i.detail?i.detail:1,this._config=i}render(){return this._config&&this.hass?this._error?r.qy` <ha-alert alert-type="error"> ${this.hass.localize("ui.components.history_charts.error")}: ${this._error.message||this._error.code} </ha-alert> `:this._coordinates&&!this._coordinates.length?r.qy` <div class="container"> <div class="info">No state history found.</div> </div> `:r.qy` <hui-graph-base ?loading=${this._loading} .coordinates=${this._coordinates}></hui-graph-base> `:r.s6}_handleClick(){(0,a.r)(this,"hass-more-info",{entityId:this._config?.entity??null})}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._handleClick),this.hasUpdated&&this._config&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){(0,h.x)(this.hass.config,"history")&&!this._subscribed&&this._config&&(this._setLoadingCoordinates(),this._subscribed=(0,d.IQ)(this.hass,t=>{if(this._subscribed&&this._config){if(this._history=t,!this._history[this._config.entity]?.length){const t=this.hass.states[this._config.entity];t&&(this._history[this._config.entity]=(0,d.Lj)(t))}this._computeCoordinates()}},this._config.hours_to_show,[this._config.entity]).catch(t=>{this._subscribed=void 0,this._error=t}),this._setRedrawTimer())}_setLoadingCoordinates(){if(!this._config||!this.hass)return;const t=this.hass.states[this._config.entity];if(!t)return;const i=this.clientWidth||this.offsetWidth,{points:s}=(0,u.a)((0,d.Lj)(t),i,i/5,10,{minY:this._config.limits?.min,maxY:this._config.limits?.max});this._coordinates=s}_computeCoordinates(){if(!this._history||!this._config)return;const t=this._history[this._config.entity];if(!t?.length)return;const i=this.clientWidth||this.offsetWidth,s=Math.max(10,this._config.detail>1?Math.max(i/5,this._config.hours_to_show):this._config.hours_to_show),o=Date.now(),e=2!==this._config.detail,{points:r}=(0,u.a)(t,i,i/5,s,{minX:o-this._config.hours_to_show*y,maxX:o,minY:this._config.limits?.min,maxY:this._config.limits?.max},e);this._coordinates=r,this._loading=!1}_redrawGraph(){if(!this._history||!this._config?.hours_to_show)return;const t=this._config.entity,i=this._history[t];if(i?.length){const s=(Date.now()-60*this._config.hours_to_show*60*1e3)/1e3;let o=i.filter(t=>t.lu>=s);if(o.length!==i.length){if(!o.length||o[0].lu!==s){const t={...i[i.length-o.length-1]};t.lu=s,delete t.lc,o=[t,...o]}this._history={...this._history,[t]:o}}}this._computeCoordinates()}_setRedrawTimer(){clearInterval(this._interval),this._interval=window.setInterval(()=>this._redrawGraph(),this._config.hours_to_show>24?y:f)}_unsubscribeHistory(){clearInterval(this._interval),this._subscribed&&(this._subscribed.then(t=>t?.()).catch(()=>{}),this._subscribed=void 0),this._history=void 0}updated(t){if(this._config&&this.hass)if(t.has("_config")){const i=t.get("_config");i&&this._subscribed&&i.entity===this._config.entity||(this._unsubscribeHistory(),this._subscribeHistory())}else this.isConnected&&!this._subscribed&&!this._error&&t.has("hass")&&this._subscribeHistory()}constructor(...t){super(...t),this._loading=!0}}p.styles=r.AH`:host{cursor:pointer;display:block}.container{justify-content:center;padding-bottom:20%;display:flex;position:relative}.info{color:var(--secondary-text-color);position:absolute;top:calc(50% - 16px)}`,(0,e.Cg)([(0,n.MZ)({attribute:!1})],p.prototype,"hass",void 0),(0,e.Cg)([(0,n.MZ)()],p.prototype,"type",void 0),(0,e.Cg)([(0,n.wk)()],p.prototype,"_config",void 0),(0,e.Cg)([(0,n.wk)()],p.prototype,"_coordinates",void 0),(0,e.Cg)([(0,n.wk)()],p.prototype,"_loading",void 0),(0,e.Cg)([(0,n.wk)()],p.prototype,"_error",void 0),p=(0,e.Cg)([(0,n.EM)("hui-graph-header-footer")],p),s.d(i,{HuiGraphHeaderFooter:()=>p}),o()}catch(t){o(t)}})}};
//# sourceMappingURL=89954.1f209ee4e0b5575b.js.map