export const __rspack_esm_id="90303";export const __rspack_esm_ids=["90303"];export const __webpack_modules__={46754(t,e,a){a.r(e),a.d(e,{HuiStatisticCardEditor:()=>g});a(18111),a(7588),a(61701);var i=a(62826),s=a(96196),o=a(44457),n=a(22786),c=a(63533),r=a(1087),l=a(19459),d=(a(52763),a(23528)),h=a(30345),p=a(84698),_=a(44155);const m=(0,c.kp)(p.H,(0,c.Ik)({entity:(0,c.lq)((0,c.Yj)()),name:(0,c.lq)(_.q),icon:(0,c.lq)((0,c.Yj)()),unit:(0,c.lq)((0,c.Yj)()),stat_type:(0,c.lq)((0,c.Yj)()),period:(0,c.lq)((0,c.bz)()),theme:(0,c.lq)((0,c.Yj)()),footer:(0,c.lq)(h.zb),collection_key:(0,c.lq)((0,c.Yj)())})),y=["mean","min","max","change"],u={mean:"mean",min:"min",max:"max",change:"sum"},f={today:{calendar:{period:"day"}},yesterday:{calendar:{period:"day",offset:-1}},this_week:{calendar:{period:"week"}},last_week:{calendar:{period:"week",offset:-1}},this_month:{calendar:{period:"month"}},last_month:{calendar:{period:"month",offset:-1}},this_year:{calendar:{period:"year"}},last_year:{calendar:{period:"year",offset:-1}}};class g extends s.WF{setConfig(t){(0,c.vA)(t,m),this._config=t,this._fetchMetadata()}firstUpdated(){this._fetchMetadata().then(()=>{!this._config?.stat_type&&this._config?.entity&&(0,r.r)(this,"config-changed",{config:{...this._config,stat_type:this._metadata?.has_sum?"change":"mean"}})})}render(){if(!this.hass||!this._config)return s.s6;const t=this._data(this._config),e=this._schema("string"==typeof t.period?t.period:void 0,this.hass.localize,this._metadata);return s.qy` <ha-form .hass="${this.hass}" .data="${t}" .schema="${e}" .computeLabel="${this._computeLabelCallback}" @value-changed="${this._valueChanged}"></ha-form> `}async _fetchMetadata(){this.hass&&this._config&&(this._metadata=(await(0,d.Wr)(this.hass,[this._config.entity]))[0])}async _valueChanged(t){const e={...t.detail.value};if(Object.keys(e).forEach(t=>""===e[t]&&delete e[t]),"string"==typeof e.period){const t=f[e.period];t&&(e.period=t)}if(e.stat_type&&e.entity&&e.entity!==this._metadata?.statistic_id){const t=(await(0,d.Wr)(this.hass,[e.entity]))?.[0];t&&!t.has_sum&&"change"===e.stat_type&&(e.stat_type="mean"),t&&t.mean_type===d.ED.NONE&&"change"!==e.stat_type&&(e.stat_type="change")}if(!e.stat_type&&e.entity){const t=(await(0,d.Wr)(this.hass,[e.entity]))?.[0];e.stat_type=t?.has_sum?"change":"mean"}(0,r.r)(this,"config-changed",{config:e})}constructor(...t){super(...t),this._data=(0,n.A)(t=>{if(!t||!t.period)return t;for(const[e,a]of Object.entries(f))if((0,l.b)(a,t.period))return{...t,period:e};return t}),this._schema=(0,n.A)((t,e,a)=>[{name:"entity",required:!0,selector:{statistic:{}}},{name:"stat_type",required:!0,selector:{select:{multiple:!1,options:y.map(t=>({value:t,label:e(`ui.panel.lovelace.editor.card.statistic.stat_type_labels.${t}`),disabled:!a||!(0,d.nN)(a,u[t])}))}}},{name:"period",required:!0,selector:t&&t in f?{select:{multiple:!1,options:Object.keys(f).map(t=>({value:t,label:e(`ui.panel.lovelace.editor.card.statistic.periods.${t}`)||t}))}}:{object:{}}},{name:"name",selector:{entity_name:{}},context:{entity:"entity"}},{type:"grid",name:"",schema:[{name:"icon",selector:{icon:{}},context:{icon_entity:"entity"}},{name:"unit",selector:{text:{}}},{name:"theme",selector:{theme:{}}}]}]),this._computeLabelCallback=t=>"period"===t.name?this.hass.localize("ui.panel.lovelace.editor.card.statistic.period"):"theme"===t.name?`${this.hass.localize("ui.panel.lovelace.editor.card.generic.theme")} (${this.hass.localize("ui.panel.lovelace.editor.card.config.optional")})`:this.hass.localize(`ui.panel.lovelace.editor.card.generic.${t.name}`)}}(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"hass",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_config",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_metadata",void 0),g=(0,i.Cg)([(0,o.EM)("hui-statistic-card-editor")],g)},84698(t,e,a){a.d(e,{H:()=>s});var i=a(63533);const s=(0,i.Ik)({type:(0,i.Yj)(),view_layout:(0,i.bz)(),layout_options:(0,i.bz)(),grid_options:(0,i.bz)(),visibility:(0,i.bz)(),disabled:(0,i.lq)((0,i.zM)())})},55904(t,e,a){a.d(e,{J:()=>o});var i=a(63533),s=a(91408);const o=(0,i.Ik)({entity:(0,i.Yj)(),name:(0,i.lq)((0,i.Yj)()),icon:(0,i.lq)((0,i.Yj)()),image:(0,i.lq)((0,i.Yj)()),show_name:(0,i.lq)((0,i.zM)()),show_icon:(0,i.lq)((0,i.zM)()),tap_action:(0,i.lq)(s.kn),hold_action:(0,i.lq)(s.kn),double_tap_action:(0,i.lq)(s.kn)})},30345(t,e,a){a.d(e,{oe:()=>r,zb:()=>l});var i=a(63533),s=a(91408),o=a(55904);const n=(0,i.Ik)({type:(0,i.Yj)(),image:(0,i.Yj)(),tap_action:(0,i.lq)(s.kn),hold_action:(0,i.lq)(s.kn),double_tap_action:(0,i.lq)(s.kn),alt_text:(0,i.lq)((0,i.Yj)())}),c=(0,i.Ik)({type:(0,i.Yj)(),entities:(0,i.YO)(o.J)}),r=(0,i.Ik)({type:(0,i.Yj)(),entity:(0,i.Yj)(),detail:(0,i.lq)((0,i.ai)()),hours_to_show:(0,i.lq)((0,i.ai)())}),l=(0,i.OR)(t=>{if(t&&"object"==typeof t&&"type"in t)switch(t.type){case"buttons":return c;case"graph":return r;case"picture":return n}return(0,i.KC)([c,r,n])})}};
//# sourceMappingURL=90303.f199fea6206d7e81.js.map