import{k as yt,j as T,t as _t,h as lt,m as w,n as k,p as c,q as B,i as b,v as G,A as I,x as W,e as nt,s as St,f as at,w as f,F as it}from"./web.Os7kOAdY.js";import{g as ot,t as wt}from"./i18n-runtime._BAkvU05.js";var Ct=I("<div class=panel style=display:flex;flex-direction:column;gap:14px><div style=display:flex;gap:8px><button></button><button></button></div><div class=tool-grid-2><!$><!/><div class=tool-field><span class=tool-label></span><input class=tool-input type=number step=0.1></div></div><div class=tool-field style=max-width:200px><span class=tool-label></span><input class=tool-input type=number></div><!$><!/><p class=tool-hint>"),st=I("<div class=tool-field><span class=tool-label></span><input class=tool-input type=number>"),Mt=I("<pre class=tool-pre style=font-size:14px>"),Ft=I("<div style=overflow-x:auto><svg style=width:100%;max-width:600px;height:auto;font-family:system-ui><path fill=rgba(59,130,246,0.15)></path><path fill=none stroke=#3b82f6 stroke-width=2></path><!$><!/><!$><!/>"),Lt=I("<svg><line stroke=#e5e7eb stroke-width=0.5></svg>",!1,!0,!1),kt=I("<svg><text text-anchor=end font-size=10 fill=#666></svg>",!1,!0,!1),It=I("<svg><text text-anchor=middle font-size=10 fill=#666><!$><!/><!$><!/><!$><!/></svg>",!1,!0,!1);function Tt(){const[J,K]=T(ot(),{equals:!1}),o=t=>wt(t,J());_t(()=>{const t=g=>{const s=g.detail?.locale;s&&K(s)};window.addEventListener("taitan:locale-change",t),K(ot()),St(()=>window.removeEventListener("taitan:locale-change",t))});const[N,O]=T("lump"),[Y,rt]=T("100000"),[Z,ct]=T("2000"),[Q,ut]=T("8"),[U,vt]=T("10"),y=lt(()=>{const t=(parseFloat(Q())||0)/100,g=parseInt(U())||0;if(g<=0||t<0)return null;const s=[];if(N()==="lump"){const _=parseFloat(Y())||0;for(let d=0;d<=g;d++)s.push({year:d,value:_*Math.pow(1+t,d)})}else{const _=parseFloat(Z())||0,d=t/12;for(let m=0;m<=g;m++){const D=m*12,C=D===0?0:_*((Math.pow(1+d,D)-1)/d)*(1+d);s.push({year:m,value:C})}}const e=s[s.length-1]?.value||0,p=N()==="lump"?parseFloat(Y())||0:(parseFloat(Z())||0)*g*12,x=e-p;return{yearlyData:s,finalValue:e,totalInvested:p,profit:x}}),v=lt(()=>{const t=y()?.yearlyData;if(!t||t.length<2)return null;const g=600,s=250,e={top:20,right:20,bottom:30,left:60},p=g-e.left-e.right,x=s-e.top-e.bottom,_=Math.max(...t.map(a=>a.value)),d=0,m=_-d||1,C=t.map((a,F)=>{const i=e.left+F/(t.length-1)*p,r=e.top+x-(a.value-d)/m*x;return`${i},${r}`}).map((a,F)=>F===0?`M${a}`:`L${a}`).join(" "),q=C+` L${e.left+p},${e.top+x} L${e.left},${e.top+x} Z`,R=[],A=m/4;for(let a=0;a<=4;a++){const F=d+A*a,i=e.top+x-a/4*x;R.push({value:F,y:i})}const M=[],H=Math.max(1,Math.floor(t.length/5));for(let a=0;a<t.length;a+=H)M.push({year:t[a].year,x:e.left+a/(t.length-1)*p});return M[M.length-1]?.year!==t[t.length-1].year&&M.push({year:t[t.length-1].year,x:e.left+p}),{width:g,height:s,padding:e,pathD:C,areaD:q,yLabels:R,xLabels:M}}),j=t=>t>=1e4?new Intl.NumberFormat(J(),{notation:"compact",maximumFractionDigits:2}).format(t):t.toFixed(2);return(()=>{var t=w(Ct),g=t.firstChild,s=g.firstChild,e=s.nextSibling,p=g.nextSibling,x=p.firstChild,[_,d]=k(x.nextSibling),m=_.nextSibling,D=m.firstChild,C=D.nextSibling,q=p.nextSibling,R=q.firstChild,A=R.nextSibling,M=q.nextSibling,[H,a]=k(M.nextSibling),F=H.nextSibling;return s.$$click=()=>O("lump"),c(s,()=>o("一次性投资")),e.$$click=()=>O("regular"),c(e,()=>o("定期定额投资")),c(p,(()=>{var i=B(()=>N()==="lump");return()=>i()?(()=>{var r=w(st),$=r.firstChild,S=$.nextSibling;return c($,()=>o("本金（元）")),S.$$input=E=>rt(E.currentTarget.value),b(()=>W(S,"value",Y())),G(),r})():(()=>{var r=w(st),$=r.firstChild,S=$.nextSibling;return c($,()=>o("每月投入（元）")),S.$$input=E=>ct(E.currentTarget.value),b(()=>W(S,"value",Z())),G(),r})()})(),_,d),c(D,()=>o("年化收益率（%）")),C.$$input=i=>ut(i.currentTarget.value),c(R,()=>o("投资年限（年）")),A.$$input=i=>vt(i.currentTarget.value),c(t,(()=>{var i=B(()=>!!y());return()=>i()&&[(()=>{var r=w(Mt);return c(r,()=>`${o("累计投入")}: ${j(y().totalInvested)} ${o("元")}
${o("最终价值")}: ${j(y().finalValue)} ${o("元")}
${o("投资收益")}: ${j(y().profit)} ${o("元")}
${o("收益率")}: ${y().totalInvested>0?(y().profit/y().totalInvested*100).toFixed(1):"0"}%`),r})(),B(()=>B(()=>!!v())()&&(()=>{var r=w(Ft),$=r.firstChild,S=$.firstChild,E=S.nextSibling,dt=E.nextSibling,[X,$t]=k(dt.nextSibling),gt=X.nextSibling,[pt,ht]=k(gt.nextSibling);return c($,at(it,{get each(){return v().yLabels},children:u=>[(()=>{var l=w(Lt);return b(n=>{var h=v().padding.left,L=u.y,P=v().padding.left+(v().width-v().padding.left-v().padding.right),V=u.y;return h!==n.e&&f(l,"x1",n.e=h),L!==n.t&&f(l,"y1",n.t=L),P!==n.a&&f(l,"x2",n.a=P),V!==n.o&&f(l,"y2",n.o=V),n},{e:void 0,t:void 0,a:void 0,o:void 0}),l})(),(()=>{var l=w(kt);return c(l,()=>j(u.value)),b(n=>{var h=v().padding.left-5,L=u.y+4;return h!==n.e&&f(l,"x",n.e=h),L!==n.t&&f(l,"y",n.t=L),n},{e:void 0,t:void 0}),l})()]}),X,$t),c($,at(it,{get each(){return v().xLabels},children:u=>(()=>{var l=w(It),n=l.firstChild,[h,L]=k(n.nextSibling),P=h.nextSibling,[V,ft]=k(P.nextSibling),xt=V.nextSibling,[mt,bt]=k(xt.nextSibling);return c(l,()=>o("第"),h,L),c(l,()=>u.year,V,ft),c(l,()=>o("年"),mt,bt),b(z=>{var tt=u.x,et=v().height-5;return tt!==z.e&&f(l,"x",z.e=tt),et!==z.t&&f(l,"y",z.t=et),z},{e:void 0,t:void 0}),l})()}),pt,ht),b(u=>{var l=`0 0 ${v().width} ${v().height}`,n=v().areaD,h=v().pathD;return l!==u.e&&f($,"viewBox",u.e=l),n!==u.t&&f(S,"d",u.t=n),h!==u.a&&f(E,"d",u.a=h),u},{e:void 0,t:void 0,a:void 0}),r})())]})(),H,a),c(F,()=>o("假设年化收益率恒定，复利计算，不考虑通胀和税费。定投按月末投入计算。")),b(i=>{var r=`tool-btn ${N()==="lump"?"active":""}`,$=`tool-btn ${N()==="regular"?"active":""}`;return r!==i.e&&nt(s,i.e=r),$!==i.t&&nt(e,i.t=$),i},{e:void 0,t:void 0}),b(()=>W(C,"value",Q())),b(()=>W(A,"value",U())),G(),t})()}yt(["click","input"]);export{Tt as default};
