var F=Object.defineProperty;var I=(c,n,o)=>n in c?F(c,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):c[n]=o;var S=(c,n,o)=>I(c,typeof n!="symbol"?n+"":n,o);import{C as j,j as A,L as R,P as $,l as z,h as K,p as M,f as U,n as k}from"./index-CJMosIp2.js";import{k as q,u as G,B as w,f as m,$ as r,I as H,K as g,s as J,c as l,b as d,z as i,w as u,o as O,x as v,y as p}from"./index-DPl16C00.js";import{f as D}from"./utils-D98hIld_.js";import{V as Q}from"./VToolbar-CbiRZXlD.js";import{V as X}from"./VDivider-Dr0TEagO.js";import{b,V as h,a as y}from"./VCard-CJTiHjO-.js";import"./index-w-dkzpPh.js";import"./VImg-B-97Yzkt.js";const Y={class:"v-full bg-background w-full justify-center p-4"},Z={style:{height:"384px"}},ee={style:{height:"384px"}},ce=q({__name:"Forecast",setup(c){const n=G(),o=w(),f=w(""),C=["red","pink","purple","deep-purple","blue","light-blue","cyan","teal","green","light-green","lime","organe","deep-orange","brown","blue-grey"];class V{constructor(){S(this,"index",0)}getNextColor(){const a=C[this.index++];return this.index>=C.length&&(this.index=0),a}}function x(e){switch(e){case"pv":return n.current.value.colors.sun;case"pv_forecast":return n.current.value.colors.sun;case"consumption":return n.current.value.colors.grid;case"no_var_loads":return n.current.value.colors.grid;default:return null}}function _(e){switch(e){case"pv":return r("forecast.pv");case"pv_forecast":return r("forecast.pv_forecast");case"consumption":return r("forecast.consumption");case"no_var_loads":return r("forecast.no_var_loads");default:return g.getDeviceInfo(e).name}}function L(e){if(e&&e.series){let a=new V;return e.series.filter(t=>t.name!="cost_profit").map(t=>{if(t.name=="pv"||t.name=="no_var_loads"){let s=x(t.name);return{label:_(t.name),data:t.data,fill:!1,backgroundColor:s,borderColor:s,borderDash:[5,5],borderWidth:2,pointStyle:!1}}else if(t.name=="pv_forecast"||t.name=="consumption"){let s=x(t.name);return{label:_(t.name),data:t.data,fill:!1,backgroundColor:s,borderColor:s,borderWidth:2,pointStyle:!1}}else{let s=a.getNextColor();return{label:_(t.name),data:t.data,fill:!1,backgroundColor:s,borderColor:s,stepped:!0,borderWidth:2,pointStyle:!1}}})}return[]}function T(e){return e&&e.series?e.series.filter(a=>a.name=="cost_profit").map(a=>{const t="blue";return{label:r("forecast.cost_profit"),data:a.data,fill:!1,backgroundColor:t,borderColor:t,borderWidth:2,pointStyle:!1,stepped:!0}}):[]}const W=m(()=>{var e;return{labels:(e=o.value)==null?void 0:e.time.map(a=>new Date(a).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})),datasets:L(o.value)}}),P=m(()=>{var e;return{labels:(e=o.value)==null?void 0:e.time.map(a=>new Date(a).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})),datasets:T(o.value)}}),N=m(()=>{var a;const e=(a=o.value)==null?void 0:a.cost;return e?e<0?r("forecast.total_cost")+": "+-e.toFixed(2)+" "+f.value:r("forecast.total_profit")+": "+e.toFixed(2)+" "+f.value:"unknown"}),B={responsive:!0,maintainAspectRatio:!1,plugins:{datalabels:{display:!1}},scales:{y:{title:{display:!0,text:"W"}}}},E=m(()=>({responsive:!0,maintainAspectRatio:!1,plugins:{datalabels:{display:!1}},scales:{y:{title:{display:!0,text:f.value}}}}));return j.register(A,R,$,z,K,M,U),H(async()=>{o.value=await g.getForecast();const e=await g.getConfig();f.value=e.home_assistant.currency,console.log(e.home_assistant)}),(e,a)=>(O(),J("div",null,[l(Q,{color:"transparent",title:i(r)("app.forecast")},null,8,["title"]),l(X),d("div",Y,[l(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[l(h,null,{default:u(()=>[v(p(i(r)("forecast.summary")),1)]),_:1}),l(y,null,{default:u(()=>{var t,s;return[d("div",null,p(N.value),1),d("div",null,p(i(r)("consumption")+": "+i(D)((t=o.value)==null?void 0:t.consumed_energy,"kWh")),1),d("div",null,p(i(r)("home_card.solar_production")+": "+i(D)((s=o.value)==null?void 0:s.solar_energy,"kWh")),1)]}),_:1})]),_:1}),l(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[l(h,null,{default:u(()=>[v(p(i(r)("forecast.energy")),1)]),_:1}),l(y,null,{default:u(()=>[d("div",Z,[l(i(k),{data:W.value,options:B},null,8,["data"])])]),_:1})]),_:1}),l(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[l(h,null,{default:u(()=>[v(p(i(r)("forecast.cost_profit")),1)]),_:1}),l(y,null,{default:u(()=>[d("div",ee,[l(i(k),{data:P.value,options:E.value},null,8,["data","options"])])]),_:1})]),_:1})])]))}});export{ce as default};
