import"../chunks/DsnmJJEf.js";import{p as We,k as u,q as j,v as me,i as a,g as e,u as l,w as Ye,a as qe,f as Z,m as T,s as F,h as g,l as U,n as se,x as ye,F as Ge}from"../chunks/DaF1Dxyz.js";import{i as _}from"../chunks/DBNwVM39.js";import{b as He}from"../chunks/CWOq4JsP.js";import{r as Je,n as Ke,c as Qe,p as Xe,M as Ze}from"../chunks/CIKjqre7.js";import{M as _e}from"../chunks/D-_MH_UY.js";import{R as ue}from"../chunks/2X4ub8Nv.js";import{g as et,C as tt,a as at,o as rt,r as ot,b as nt}from"../chunks/DCB4peFK.js";import{r as lt,n as st,h as Pe,D as it,g as ct,E as ut,F as ge,b as gt,c as pt,e as dt,W as Ne}from"../chunks/CWmDRfqq.js";import{T as ft}from"../chunks/BXE_l9v0.js";import{E as pe}from"../chunks/B-GchW_I.js";import{u as ht}from"../chunks/M_R3-ht0.js";function vt(M,ee,O,te,ae,W,B,Y,w,s,b,p,C){const n={},v=["capacity_type"];B=="technology"?(n.technology=Y,n.location=te,v.push("location")):(n.location=w,n.technology=ae,v.push("technology")),s=="storage"&&(n.capacity_type=[b]);let i=M.filterByCriteria(n).filterDataByIndex(p.map(d=>W.indexOf(Number(d)))).groupBy(v);return C&&(i=i.normalize()),i.toArray().map(d=>{const x=B==="technology"?d.index.location:d.index.technology,D=st(x);return{label:x,data:d.data,borderColor:D,backgroundColor:O!==void 0?Xe.draw(O,Pe(D)):Pe(D),stack:ee}})}function mt(M,ee,O,te,ae,W,B,Y,w,s,b,p){if(w==null||Y.length==0||W.length==0||B.length==0||M.length===0)return[[],[]];lt(),Je();const C=[];return[ae.flatMap((v,i)=>{if(v===null||!M[i]?.length)return[];const d=et(v.solution_name,v.scenario_name),x=i>0?Ke():void 0;return C.push(Qe(d,x)),vt(M[i],d,x,ee,O,te,b,B,Y,w,s,W,p)}),C]}var yt=Z(`<div>Select the variable which to shown on the plot: <ul class="ml-4 list-outside list-disc"><li>The variable "capacity" shows the total capacity in a given year and consists of
										the sum of existing capacities, previously installed capacities, and new
										capacity additions.</li> <li>The variable "capacity_addition" shows only the capacity which is newly
										installed in the system in the given year.</li></ul></div>`),_t=Z("<!> <!> <!>",1),bt=Z(`Aggregate capacities belonging to the same node or technology. <ul class="ml-4 list-outside list-disc"><li>Choosing "Node" will show the capacity allocations per technology for each node
									(selected in the "Nodes" filter below).</li> <li>Choosing "Technology" will show the capacity allocations per node for each
									technology (selected in the "Technologies" filter below).</li></ul>`,1),xt=Z("<!> <!> <!> <!>",1),St=Z("<!> <!> <!>",1),Tt=Z("<!> <!>",1);function Ft(M,ee){We(ee,!0),ht();let O=u(j([]));const te=["capacity","capacity_addition"],ae={capacity:"Capacity",capacity_addition:"Capacity Addition"},W=["conversion","storage","transport"],B=["energy","power"],Y=[{label:"Node",value:"node"},{label:"Technology",value:"technology"}];let w=u(j([])),s=u(j([null])),b=u("capacity"),p=u("conversion"),C=u("energy"),n=u(null),v=u("technology"),i=u(!1),d=u(j([])),x=u(j([])),D=u(j([])),I=u(!1),E=u(!1),R=l(()=>e(s).some(t=>t===null)),be=u(j({})),xe=l(()=>{const t=e(p)=="storage"?e(C):"power";return e(be)[e(z)[0]+"_"+t]||""}),de=u(void 0),ke=l(()=>e(D).map(t=>t.toString()));function De(){return{maintainAspectRatio:!1,scales:{x:{stacked:!0,title:{display:!0,text:"Year"}},y:{stacked:!0,title:{display:!0,text:`${ae[e(b)]}`+(e(i)?"":` [${e(xe)}]`)},min:e(i)?0:void 0,max:e(i)?1:void 0}},interaction:{intersect:!1,mode:"nearest",axis:"x"}}}const Ie={tooltip:{callbacks:{label:t=>`${t.dataset.label}: ${t.formattedValue}`+(e(i)?"":` ${e(xe)}`),title:t=>{if(t.length>0)return`${t[0].label} - ${t[0].dataset.stack}`}}}};let Le=l(()=>e(s)[0]==null?"":[e(s)[0].solution_name.split(".").pop(),e(s)[0].scenario_name,e(b),e(p),e(n)].join("_")),Oe=l(()=>{if(e(R)||e(p)===null)return[];const t={conversion:"set_conversion_technologies",storage:"set_storage_technologies",transport:"set_transport_technologies"}[e(p)];return e(s).map($=>$.detail.system[t]||[])}),Se=l(()=>e(R)?[]:dt(e(s).flatMap(t=>Object.values(t.detail.reference_carrier))).sort()),z=l(()=>{if(e(p)===null||e(n)===null||e(R))return[];const t=new Set;return e(s).forEach(($,f)=>{(e(Oe)[f]??[]).forEach(P=>{$.detail.reference_carrier[P]===e(n)&&t.add(P)})}),Array.from(t).sort()}),re=l(()=>{if(e(R))return[];const t=new Set;return e(O).forEach($=>{$.forEach(({index:{technology:f,location:P}})=>{e(z).includes(f)&&t.add(P)})}),Array.from(t).sort()});me(()=>{a(x,e(z),!0)}),me(()=>{a(d,e(re),!0)}),me(()=>{e(s),e(b),e(p),e(C),e(n),Ye(()=>{a(v,"node"),a(i,!1),a(d,e(re),!0),a(x,e(z),!0),a(D,e(w).map(t=>t.toString()),!0),Ee()})});async function Ee(){if(e(n)===null||e(R))return;a(E,!0);const t=e(s),$=await Promise.all(t.map(f=>ct(f.solution_name,[e(b)],f.scenario_name,e(n))));a(O,$.map(f=>ut.fromRows(f[e(b)]?.data??[])),!0),$[0]?.unit?.data&&a(be,Object.fromEntries($[0].unit.data.map(f=>[f.technology+"_"+f.capacity_type,f[0]||f.units])),!0),a(E,!1)}let Ae=l(()=>mt(e(O),e(re),e(z),e(w),e(s),e(D),e(x),e(d),e(p),e(C),e(v),e(i))),Te=l(()=>Ge(e(Ae),2)),we=l(()=>e(Te)[0]),Fe=l(()=>e(Te)[1]);it(M,{parentTitle:"The Transition Pathway",pageTitle:"Capacity",subtitle:"Annual capacity and capacity addition",filters:P=>{var V=Tt(),ie=T(V);ge(ie,{title:"Solution Selection",children:(m,q)=>{{let G=l(()=>e(E)||e(I));Ze(m,{get disabled(){return e(G)},get solutions(){return e(s)},set solutions(N){a(s,N,!0)},get years(){return e(w)},set years(N){a(w,N,!0)},get loading(){return e(I)},set loading(N){a(I,N,!0)}})}}});var fe=F(ie,2);{var he=m=>{var q=St(),G=T(q);ge(G,{title:"Carrier Selection",children:(S,H)=>{{const oe=y=>{se();var L=ye(`Select the energy carrier for which to view results. Only capacities of technologies
						which have the selected carrier as the reference carrier are shown.`);g(y,L)};let h=l(()=>e(E)||e(I));gt(S,{label:"Carrier",get options(){return e(Se)},get disabled(){return e(h)},urlParam:"car",unsetIfInvalid:!0,get value(){return e(n)},set value(y){a(n,y,!0)},helpText:oe,$$slots:{helpText:!0}})}}});var N=F(G,2);{var ve=S=>{ge(S,{title:"Variable Selection",children:(H,oe)=>{var h=_t(),y=T(h);{const c=r=>{var o=yt();g(r,o)};let k=l(()=>e(E)||e(I));ue(y,{label:"Variable",get options(){return te},get disabled(){return e(k)},urlParam:"var",unsetIfInvalid:!0,get value(){return e(b)},set value(r){a(b,r,!0)},helpText:c,$$slots:{helpText:!0}})}var L=F(y,2);{const c=r=>{se();var o=ye("Select whether to show capacities for conversion, storage, or transport technologies.");g(r,o)};let k=l(()=>e(E)||e(I));ue(L,{label:"Technology Type",get options(){return W},get disabled(){return e(k)},urlParam:"tech",unsetIfInvalid:!0,get value(){return e(p)},set value(r){a(p,r,!0)},helpText:c,$$slots:{helpText:!0}})}var J=F(L,2);{var ne=c=>{{let k=l(()=>e(E)||e(I));ue(c,{label:"Storage Type",get options(){return B},get disabled(){return e(k)},urlParam:"stor",unsetIfInvalid:!0,get value(){return e(C)},set value(r){a(C,r,!0)}})}};_(J,c=>{e(p)=="storage"&&c(ne)})}g(H,h)}})};_(N,S=>{e(n)!==null&&S(ve)})}var A=F(N,2);{var ce=S=>{ge(S,{title:"Data Selection",children:(H,oe)=>{var h=xt(),y=T(h);ue(y,{label:"Aggregation",get options(){return Y},get value(){return e(v)},set value(o){a(v,o,!0)},helpText:o=>{se();var le=bt();se(),g(o,le)},$$slots:{helpText:!0}});var L=F(y,2);ft(L,{label:"Normalization",get value(){return e(i)},set value(o){a(i,o,!0)},helpText:o=>{se();var le=ye("Normalize the bars to have a height of one.");g(o,le)},$$slots:{helpText:!0}});var J=F(L,2);{var ne=r=>{_e(r,{label:"Technologies",get options(){return e(z)},get value(){return e(x)},set value(o){a(x,o,!0)}})},c=r=>{_e(r,{label:"Nodes",get options(){return e(re)},get value(){return e(d)},set value(o){a(d,o,!0)}})};_(J,r=>{e(v)=="technology"?r(ne):r(c,!1)})}var k=F(J,2);{let r=l(()=>e(w).map(o=>o.toString()));_e(k,{label:"Years",get options(){return e(r)},get value(){return e(D)},set value(o){a(D,o,!0)}})}g(H,h)}})};_(A,S=>{e(n)!==null&&S(ce)})}g(m,q)};_(fe,m=>{!e(I)&&!e(R)&&m(he)})}g(P,V)},buttons:P=>{{let V=l(()=>[e(de)]);tt(P,{get charts(){return e(V)},downloadable:!0})}},mainContent:P=>{var V=U(),ie=T(V);{var fe=m=>{pt(m)},he=m=>{var q=U(),G=T(q);{var N=A=>{Ne(A,{message:"Please select a solution"})},ve=A=>{var ce=U(),S=T(ce);{var H=h=>{pe(h,{message:"No carriers for this solution found"})},oe=h=>{var y=U(),L=T(y);{var J=c=>{Ne(c,{message:"Please select a carrier"})},ne=c=>{var k=U(),r=T(k);{var o=K=>{pe(K,{message:"No technologies for this selection found"})},le=K=>{var Ce=U(),Me=T(Ce);{var Be=Q=>{pe(Q,{message:"No locations for this selection found"})},Re=Q=>{var $e=U(),ze=T($e);{var Ve=X=>{pe(X,{message:"No data for this selection found"})},je=X=>{He(at(X,{type:"bar",get labels(){return e(ke)},getDatasets:()=>e(we),getOptions:De,get pluginOptions(){return Ie},get plotName(){return e(Le)},get patterns(){return e(Fe)},get generateLabels(){return nt},get resetLegendState(){return ot},get onClickLegend(){return rt}}),Ue=>a(de,Ue,!0),()=>e(de))};_(ze,X=>{e(we).length==0?X(Ve):X(je,!1)},!0)}g(Q,$e)};_(Me,Q=>{e(re).length==0?Q(Be):Q(Re,!1)},!0)}g(K,Ce)};_(r,K=>{e(z).length==0?K(o):K(le,!1)},!0)}g(c,k)};_(L,c=>{e(n)===null?c(J):c(ne,!1)},!0)}g(h,y)};_(S,h=>{e(Se).length==0?h(H):h(oe,!1)},!0)}g(A,ce)};_(G,A=>{e(R)?A(N):A(ve,!1)},!0)}g(m,q)};_(ie,m=>{e(I)||e(E)?m(fe):m(he,!1)})}g(P,V)}}),qe()}export{Ft as component};
