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 R,j,L as A,P as $,l as G,h as H,p as J,f as M,n as w}from"./index-CoXvh_-d.js";import{B as U,v as q,r as k,c as m,$ as r,o as z,R as v,E as K,m as l,G as d,J as i,w as u,t as O,H as g,I as p}from"./index-Cp3-A7ao.js";import{f as D}from"./utils-D98hIld_.js";import{V as Q,a as X}from"./VToolbar-jYZfQvPG.js";import{b,V as h,a as C}from"./VCard-D5wKeDng.js";import"./transition-BAtvBeuS.js";import"./index-DkrqsE6v.js";import"./VImg-tOz2PgiP.js";const Y={class:"v-full bg-background w-full justify-center p-4"},Z={class:"h-96"},ee={class:"h-96"},ce=U({__name:"Forecast",setup(c){const n=q(),o=k(),f=k(""),y=["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=y[this.index++];return this.index>=y.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 v.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"}),E={responsive:!0,maintainAspectRatio:!1,plugins:{datalabels:{display:!1}},scales:{y:{title:{display:!0,text:"W"}}}},B=m(()=>({responsive:!0,maintainAspectRatio:!1,plugins:{datalabels:{display:!1}},scales:{y:{title:{display:!0,text:f.value}}}}));return R.register(j,A,$,G,H,J,M),z(async()=>{o.value=await v.getForecast();const e=await v.getConfig();f.value=e.home_assistant.currency,console.log(e.home_assistant)}),(e,a)=>(O(),K("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(()=>[g(p(i(r)("forecast.summary")),1)]),_:1}),l(C,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(()=>[g(p(i(r)("forecast.energy")),1)]),_:1}),l(C,null,{default:u(()=>[d("div",Z,[l(i(w),{data:W.value,options:E},null,8,["data"])])]),_:1})]),_:1}),l(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[l(h,null,{default:u(()=>[g(p(i(r)("forecast.cost_profit")),1)]),_:1}),l(C,null,{default:u(()=>[d("div",ee,[l(i(w),{data:P.value,options:B.value},null,8,["data","options"])])]),_:1})]),_:1})])]))}});export{ce as default};
