var B=Object.defineProperty;var I=(c,n,o)=>n in c?B(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 j,j as A,L as M,P as R,l as $,h as J,p as O,f as Q,n as w}from"./index-72cd3ef5.js";import{M as U,Z,r as k,c as m,o as q,a3 as g,l as z,S as G,J as r,O as i,Q as d,w as u,a8 as l,_ as v,$ as p}from"./index-2a796b7e.js";import{f as D}from"./utils-6f3c77d7.js";import{V as H}from"./VToolbar-343cf9b8.js";import{V as K}from"./VDivider-d71a9ada.js";import{b,V as h,a as C}from"./VCard-e2c302fe.js";import"./VImg-9fff8259.js";import"./index-bfe34a20.js";import"./VAvatar-c55f1640.js";const X={class:"v-full w-full justify-center p-4 bg-background"},Y={class:"h-96"},ee={class:"h-96"},de=U({__name:"Forecast",setup(c){const n=Z(),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 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"}),E={responsive:!0,maintainAspectRatio:!1,plugins:{datalabels:{display:!1}},scales:{y:{title:{display:!0,text:"W"}}}},F=m(()=>({responsive:!0,maintainAspectRatio:!1,plugins:{datalabels:{display:!1}},scales:{y:{title:{display:!0,text:f.value}}}}));return j.register(A,M,R,$,J,O,Q),q(async()=>{o.value=await g.getForecast();const e=await g.getConfig();f.value=e.home_assistant.currency,console.log(e.home_assistant)}),(e,a)=>(z(),G("div",null,[r(H,{color:"transparent",title:i(l)("app.forecast")},null,8,["title"]),r(K),d("div",X,[r(b,{class:"mb-4 p-4 rounded-md elevation-2"},{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(D)((t=o.value)==null?void 0:t.consumed_energy,"kWh")),1),d("div",null,p(i(l)("home_card.solar_production")+": "+i(D)((s=o.value)==null?void 0:s.solar_energy,"kWh")),1)]}),_:1})]),_:1}),r(b,{class:"mb-4 p-4 rounded-md elevation-2"},{default:u(()=>[r(h,null,{default:u(()=>[v(p(i(l)("forecast.energy")),1)]),_:1}),r(C,null,{default:u(()=>[d("div",Y,[r(i(w),{data:W.value,options:E},null,8,["data"])])]),_:1})]),_:1}),r(b,{class:"mb-4 p-4 rounded-md elevation-2"},{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:F.value},null,8,["data","options"])])]),_:1})]),_:1})])]))}});export{de as default};
