var E=Object.defineProperty;var I=(c,n,o)=>n in c?E(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),o);import{C as R,j,L as A,P as $,l as q,h as G,p as H,f as M,n as w}from"./index-5a502f9f.js";import{B as U,x as z,r as D,c as m,o as J,R as g,q as K,D as O,m as r,I as i,H as d,w as u,$ as l,F as v,G as p}from"./index-5ee1411a.js";import{f as k}from"./utils-6f3c77d7.js";import{V as Q,a as X}from"./VToolbar-55156e00.js";import{b,V as h,a as C}from"./VCard-8ba7cfc2.js";import"./transition-cd9cc606.js";import"./index-a55adddd.js";import"./VImg-71612e97.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=z(),o=D(),f=D(""),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 l("forecast.pv");case"pv_forecast":return l("forecast.pv_forecast");case"consumption":return l("forecast.consumption");case"no_var_loads":return l("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:l("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?l("forecast.total_cost")+": "+-e.toFixed(2)+" "+f.value:l("forecast.total_profit")+": "+e.toFixed(2)+" "+f.value:"unknown"}),F={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,$,q,G,H,M),J(async()=>{o.value=await g.getForecast();const e=await g.getConfig();f.value=e.home_assistant.currency,console.log(e.home_assistant)}),(e,a)=>(K(),O("div",null,[r(Q,{color:"transparent",title:i(l)("app.forecast")},null,8,["title"]),r(X),d("div",Y,[r(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[r(h,null,{default:u(()=>[v(p(i(l)("forecast.summary")),1)]),_:1}),r(C,null,{default:u(()=>{var t,s;return[d("div",null,p(N.value),1),d("div",null,p(i(l)("consumption")+": "+i(k)((t=o.value)==null?void 0:t.consumed_energy,"kWh")),1),d("div",null,p(i(l)("home_card.solar_production")+": "+i(k)((s=o.value)==null?void 0:s.solar_energy,"kWh")),1)]}),_:1})]),_:1}),r(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[r(h,null,{default:u(()=>[v(p(i(l)("forecast.energy")),1)]),_:1}),r(C,null,{default:u(()=>[d("div",Z,[r(i(w),{data:W.value,options:F},null,8,["data"])])]),_:1})]),_:1}),r(b,{class:"elevation-2 mb-4 rounded-md p-4"},{default:u(()=>[r(h,null,{default:u(()=>[v(p(i(l)("forecast.cost_profit")),1)]),_:1}),r(C,null,{default:u(()=>[d("div",ee,[r(i(w),{data:P.value,options:B.value},null,8,["data","options"])])]),_:1})]),_:1})])]))}});export{ce as default};
