export const __rspack_esm_id="33427";export const __rspack_esm_ids=["33427"];export const __webpack_modules__={67806(t,i,s){s.a(t,async function(t,e){try{s.r(i),s.d(i,{HuiGraphHeaderFooter:()=>y});s(18111),s(22489);var o=s(62826),r=s(96196),n=s(97735),h=s(36312),a=s(1087),c=s(71727),_=s(65829),d=s(25064),l=s(13632),u=s(18721),f=(s(24672),t([_,d]));[_,d]=f.then?(await f)():f;const g=6e4,p=60*g,b=["counter","input_number","number","sensor"];class y extends r.WF{static async getConfigElement(){return await s.e("11868").then(s.bind(s,87031)),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`<div class="errors">${this._error}</div>`:this._coordinates?this._coordinates.length?r.qy` <hui-graph-base .coordinates="${this._coordinates}"></hui-graph-base> `:r.qy` <div class="container"> <div class="info">No state history found.</div> </div> `:r.qy` <div class="container"> <ha-spinner size="small"></ha-spinner> </div> `: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,"history")&&!this._subscribed&&this._config&&(this._subscribed=(0,d.IQ)(this.hass,t=>{this._subscribed&&this._config&&(this._history=t,this._computeCoordinates())},this._config.hours_to_show,[this._config.entity]).catch(t=>{this._subscribed=void 0,this._error=t}),this._setRedrawTimer())}_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),e=Date.now(),o=2!==this._config.detail,{points:r}=(0,u.a)(t,i,i/5,s,{minX:e-this._config.hours_to_show*p,maxX:e,minY:this._config.limits?.min,maxY:this._config.limits?.max},o);this._coordinates=r}_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 e=i.filter(t=>t.lu>=s);if(e.length!==i.length){if(!e.length||e[0].lu!==s){const t={...i[i.length-e.length-1]};t.lu=s,delete t.lc,e=[t,...e]}this._history={...this._history,[t]:e}}}this._computeCoordinates()}_setRedrawTimer(){clearInterval(this._interval),this._interval=window.setInterval(()=>this._redrawGraph(),this._config.hours_to_show>24?p:g)}_unsubscribeHistory(){clearInterval(this._interval),this._subscribed&&(this._subscribed.then(t=>t?.()),this._subscribed=void 0),this._history=void 0}updated(t){if(!this._config||!this.hass||!t.has("_config"))return;const i=t.get("_config");i&&this._subscribed&&i.entity===this._config.entity||(this._unsubscribeHistory(),this._subscribeHistory())}}y.styles=r.AH`:host{display:block;cursor:pointer}ha-spinner{position:absolute;top:calc(50% - 14px)}.container{display:flex;justify-content:center;position:relative;padding-bottom:20%}.info{position:absolute;top:calc(50% - 16px);color:var(--secondary-text-color)}`,(0,o.Cg)([(0,n.MZ)({attribute:!1})],y.prototype,"hass",void 0),(0,o.Cg)([(0,n.MZ)()],y.prototype,"type",void 0),(0,o.Cg)([(0,n.wk)()],y.prototype,"_config",void 0),(0,o.Cg)([(0,n.wk)()],y.prototype,"_coordinates",void 0),y=(0,o.Cg)([(0,n.EM)("hui-graph-header-footer")],y),e()}catch(t){e(t)}})}};
//# sourceMappingURL=33427.b54445e3452e478f.js.map