PageSourceSearch

https://xynergy.ai/_next/static/chunks/6168.ed43919816f98595.js

js xynergy.ai collected 2026-10-05 16:02:23 UTC 27,770 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6168],{33787:(e,t,l)=>{l.r(t),l.d(t,{LiabilitiesRepaymentPanel:()=>z});var a=l(85047),r=l(73521),n=l(56878),s=l(31615),i=l(82520),o=l(21410),c=l(866),d=l(96968),m=l(21582),h=l(6386),u=l(41178),x=l(35617),p=l(47026),y=l(21363),j=l(58661),g=l(76458),b=l(24571),f=l(15418);let v=f.k5(["proportional","priority","high-interest","low-balance","custom"]),N=f.Ik({type:v,priorityOrder:f.YO(f.Yj()).optional(),customAllocations:f.g1(f.Yj(),f.ai().nonnegative()).optional()}),M=f.Ik({liabilityId:f.Yj().min(1,"負債 ID 不能為空"),monthlyPayment:f.ai().nonnegative("每月還款金額不能為負數")}),P=f.Ik({userId:f.Yj().min(1,"userId 不能為空"),monthlyBudget:f.ai().positive("每月還款總預算必須大於 0"),strategy:N,liabilityAllocations:f.YO(M).optional(),createdAt:f.bz(),updatedAt:f.bz().optional()});var A=l(18654);let w="debtRepaymentPlans";var D=l(24385),k=l(2962),C=l(21016),R=l(7004),I=l(72287),B=l(23187),S=l(29744),T=l.n(S),F=l(60996),$=l(91595);function E({planResult:e,height:t=400}){let l=(0,$.py)(),r=(0,s.useMemo)(()=>{if(!e||0===e.liabilityPlans.length)return null;let a=Math.max(...e.liabilityPlans.map(e=>e.completionMonth),0);if(0===a)return null;let r=[];for(let e=1;e<=a;e++)(e%12==1||e===a)&&r.push(e);let n=r.map(e=>`第 ${Math.ceil(e/12)} 年`),s=e.liabilityPlans.map((e,t)=>{let a=[];r.forEach(t=>{if(t<=e.completionMonth){let l=Math.min(t-1,e.loanResult.repaymentSchedule.length-1),r=e.loanResult.repaymentSchedule[l];a.push(Math.round(r?.remainingBalance||0))}else a.push(0)});let n=[l.chart1,l.chart2,l.chart3,l.chart4,l.chart5];return{name:`${e.liabilityName} - 剩餘本金`,data:a.map(e=>({y:e,custom:{formattedValue:(0,x.C)(e)}})),color:n[t%5]||l.chart1,lineWidth:2,marker:{enabled:!1}}}),i=[],o=[];r.forEach(t=>{let l=0,a=0;e.liabilityPlans.forEach(e=>{let r=e.loanResult.repaymentSchedule[0]?.remainingBalance||0;if(t<=e.completionMonth){let n=Math.min(t-1,e.loanResult.repaymentSchedule.length-1),s=e.loanResult.repaymentSchedule[n];if(s){l+=r-s.remainingBalance;let t=e.loanResult.monthlyData[n];if(t)a+=t.interestPaid;else{let t=0;for(let l=0;l<=n;l++)t+=e.loanResult.repaymentSchedule[l]?.interest||0;a+=t}}}else l+=r,a+=e.loanResult.totalInterest}),i.push(Math.round(l)),o.push(Math.round(a))});let c=[...s,{name:"累積已還本金",data:i.map(e=>({y:e,custom:{formattedValue:(0,x.C)(e)}})),color:l.chart2,lineWidth:2,marker:{enabled:!1},dashStyle:"Dash"},{name:"累積已還利息",data:o.map(e=>({y:e,custom:{formattedValue:(0,x.C)(e)}})),color:l.chart3||l.chart1,lineWidth:2,marker:{enabled:!1},dashStyle:"Dash"}];return(0,$.dt)("line",{chart:{backgroundColor:"transparent",height:t},title:{text:void 0},xAxis:{categories:n,title:{text:"還款期間"}},yAxis:{title:{text:"金額 (新台幣)"},labels:{format:"{value:,.0f}"}},tooltip:{shared:!0,useHTML:!0,headerFormat:"<strong>{point.key}</strong><br/>",pointFormat:'<span style="color:{series.color}">{series.name}</span>: {point.custom.formattedValue}<br/>'},series:c,legend:{enabled:!0,align:"center",verticalAlign:"bottom"}})},[e,l,t]);return r?(0,a.jsx)("div",{className:"relative flex items-center justify-center",style:{height:`${t}px`},children:(0,a.jsx)(F.A,{highcharts:T(),options:r})}):(0,a.jsx)("div",{className:"flex items-center justify-center h-[400px] text-muted-foreground",children:(0,a.jsx)("p",{children:"尚無圖表資料"})})}var Z=l(87884);function H({planResult:e,height:t=500}){let l=(0,$.py)(),r=(0,s.useMemo)(()=>{let a;if(!e||0===e.liabilityPlans.length)return null;let r=new Date(e.monthlyDetails[0]?.date||new Date),n=e.totalMonths,s={};n<=12?(s={month:"%Y年%m月",day:"%m/%d"},a=2592e6):n<=60?(s={month:"%Y年%m月",year:"%Y年"},a=5184e6):(s={year:"%Y年"},a=31536e6);let i=e.liabilityPlans.map((e,t)=>{let l,a=new Date(r);-1===e.completionMonth?(l=new Date(a)).setFullYear(l.getFullYear()+50):(l=new Date(a)).setMonth(l.getMonth()+e.completionMonth-1);let n=e.loanResult.repaymentSchedule[0]?.remainingBalance||0,s=(0,D.GP)(a,"yyyy/MM/dd"),i=(0,D.GP)(l,"yyyy/MM/dd"),o=-1===e.completionMonth,c=o?`開始日期: ${s}<br/>
1還款期限: 無還款期限(僅計算利息)<br/>總還款: 持續計算中<br/>總利息: ${(0,x.C)(e.totalInterest||0)}<br/>初始金額: ${(0,x.C)(n)}`:`開始日期: ${s}<br/>完成日期: ${i}<br/>還款期間: ${e.completionMonth||0} 個月<br/>總還款: ${(0,x.C)(e.totalPayment||0)}<br/>總利息: ${(0,x.C)(e.totalInterest||0)}<br/>初始金額: ${(0,x.C)(n)}`;return{id:e.liabilityId,name:e.liabilityName+(-1===e.completionMonth?"(無還款期限)":""),start:a.getTime(),end:l.getTime(),custom:{totalPayment:e.totalPayment,totalInterest:e.totalInterest,completionMonth:e.completionMonth,initialAmount:n,isNoTerm:o,tooltipBodyHtml:c}}}),o=[l.chart1,l.chart2,l.chart3,l.chart4,l.chart5],c=e.liabilityPlans.map(e=>e.liabilityName);return{chart:{type:"xrange",backgroundColor:"transparent",height:t,zoomType:"x",scrollablePlotArea:{minWidth:50*n}},title:{text:void 0},xAxis:{type:"datetime",title:{text:"時間"},labels:{useHTML:!0,format:"{value:%Y-%m}",style:{color:l.mutedForeground},rotation:0,step:1},dateTimeLabelFormats:s,tickInterval:a,lineColor:l.border,tickColor:l.border,gridLineColor:l.muted},yAxis:{type:"category",categories:c,title:{text:"負債"},labels:{style:{color:l.text}},lineColor:l.border,tickColor:l.border,gridLineColor:l.muted,reversed:!0},tooltip:{backgroundColor:l.background,borderWidth:1,borderColor:l.border,style:{color:l.text},useHTML:!0,positioner:(e,t,l)=>{let a=l?.series?.chart,r=a?.scrollablePlotArea,n=r?.scrollingContainer?.scrollLeft??r?.scrollLeft??0,s=r?.scrollingContainer?.scrollTop??r?.scrollTop??0,i=l?.shapeArgs?.x,o=l?.shapeArgs?.width,c=l?.shapeArgs?.y,d=l?.shapeArgs?.height,m="number"==typeof i?i+("number"==typeof o?o/2:0):l?.plotX??0,h="number"==typeof c?c+("number"==typeof d?d/2:0):l?.plotY??0,u=(a.plotLeft||0)+m-n+10,x=(a.plotTop||0)+h-s-t-10;return u=Math.max(0,Math.min(u,(a.chartWidth||0)-e)),x<0&&(x=(a.plotTop||0)+h-s+10),{x:u,y:x=Math.max(0,Math.min(x,(a.chartHeight||0)-t))}},headerFormat:"<b>{point.name}</b><br/>",pointFormat:"{point.custom.tooltipBodyHtml}"},series:[{name:"償債計劃",type:"xrange",data:i.map((e,t)=>({x:e.start,x2:e.end,y:t,name:e.name,id:e.id,color:o[t%o.length],custom:e.custom})),dataLabels:{enabled:!1},pointPadding:.2,groupPadding:.3}],credits:{enabled:!1},exporting:{enabled:!1},plotOptions:{xrange:{dataLabels:{enabled:!1},states:{hover:{brightness:.1}}}},legend:{enabled:!1}}},[e,l,t]);return r?(0,a.jsx)("div",{className:"relative flex items-center justify-center",style:{height:`${t}px`},children:(0,a.jsx)(F.A,{highcharts:Z.A,options:r})}):(0,a.jsx)("div",{className:"flex items-center justify-center h-[500px] text-muted-foreground",children:(0,a.jsx)("p",{children:"尚無圖表資料"})})}var O=l(62557);let W=[{value:"high-interest",label:"高利率優先(雪球法)"},{value:"low-balance",label:"小額優先(滾雪球法)"},{value:"proportional",label:"按比例分配"}];function L({liabilities:e,monthlyBudget:t}){let[l,r]=(0,s.useState)(["high-interest","low-balance"]),n=(0,s.useMemo)(()=>0===e.length||t<=0?[]:l.map(l=>{let a=(0,y.D0)({liabilities:e,monthlyBudget:t,strategy:{type:l}});return{strategyType:l,result:a}}),[e,t,l]);return 0===e.length?(0,a.jsx)(i.Zp,{children:(0,a.jsx)(i.Wu,{className:"pt-6",children:(0,a.jsx)("p",{className:"text-center text-muted-foreground",children:"尚無負債資料"})})}):(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)(i.aR,{children:[(0,a.jsx)(i.ZB,{children:"方案比較"}),(0,a.jsx)(i.BT,{children:"比較不同還款策略的結果"})]}),(0,a.jsxs)(i.Wu,{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{children:"選擇要比較的策略"}),(0,a.jsx)("div",{className:"flex flex-wrap gap-4",children:W.map(e=>(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(O.S,{id:`strategy-${e.value}`,checked:l.includes(e.value),onCheckedChange:()=>{var t;return t=e.value,void r(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])}}),(0,a.jsx)(d.J,{htmlFor:`strategy-${e.value}`,className:"text-sm font-normal cursor-pointer",children:e.label})]},e.value))})]}),n.length>0&&(0,a.jsx)("div",{className:"mt-6",children:(0,a.jsxs)(k.XI,{children:[(0,a.jsx)(k.A0,{children:(0,a.jsxs)(k.Hj,{children:[(0,a.jsx)(k.nd,{children:"策略"}),(0,a.jsx)(k.nd,{className:"text-right",children:"總還款期間"}),(0,a.jsx)(k.nd,{className:"text-right",children:"總利息"}),(0,a.jsx)(k.nd,{className:"text-right",children:"完成日期"})]})}),(0,a.jsx)(k.BF,{children:n.map(({strategyType:e,result:t})=>{let l=W.find(t=>t.value===e)?.label||e,r=t.liabilityPlans.some(e=>-1===e.completionMonth);return(0,a.jsxs)(k.Hj,{children:[(0,a.jsx)(k.nA,{className:"font-medium",children:l}),(0,a.jsx)(k.nA,{className:"text-right",children:r?"無還款期限":`${t.totalMonths} 個月`}),(0,a.jsx)(k.nA,{className:"text-right",children:t.totalInterest===1/0?"持續計算中":(0,x.C)(t.totalInterest)}),(0,a.jsx)(k.nA,{className:"text-right",children:r?"無還款期限":(0,D.GP)(new Date(t.summary.completionDate),"yyyy/MM/dd")})]},e)})})]})})]})]})}var Y=l(38187),J=l(15203),V=l(63533),G=l(10250),X=l(75020);function _({planResult:e}){let t=(0,s.useMemo)(()=>
1{if(!e)return null;if(!e||0===e.monthlyDetails.length)return null;let t=new Date;for(let l of(t.setHours(0,0,0,0),e.monthlyDetails)){let e=new Date(l.date);if(e.setHours(0,0,0,0),e>=t)return e}let l=e.monthlyDetails[e.monthlyDetails.length-1];return l?new Date(l.date):null},[e]),l=(0,s.useMemo)(()=>e?function(e){if(!e||0===e.liabilityPlans.length)return{overallProgress:0,milestones:[]};let t=new Date;t.setHours(0,0,0,0);let l=e.monthlyDetails||[];if(0===l.length)return{overallProgress:0,milestones:[]};let a=new Date(l[0].date);if(a.setHours(0,0,0,0),t<a)return{overallProgress:0,milestones:[{percentage:25,reached:!1,label:"完成 25%"},{percentage:50,reached:!1,label:"完成 50%"},{percentage:75,reached:!1,label:"完成 75%"},{percentage:100,reached:!1,label:"完成 100%"}]};let r=0;for(let e of l){let l=new Date(e.date);if(l.setHours(0,0,0,0),l<=t)r=Math.max(r,e.month);else break}let{totalPrincipal:n,paidPrincipal:s}=e.liabilityPlans.reduce((e,t)=>{let l=t.loanResult.repaymentSchedule||[];if(0===l.length)return e;let a=l[0]?.remainingBalance??0;if(!(a>0))return e;let n=Math.max(0,Math.min(l.length-1,r-1)),s=l[n]?.remainingBalance??l[l.length-1]?.remainingBalance??0;return e.totalPrincipal+=a,e.paidPrincipal+=Math.max(0,a-s),e},{totalPrincipal:0,paidPrincipal:0}),i=n>0?s/n*100:0;return{overallProgress:Math.min(100,Math.max(0,i)),milestones:[{percentage:25,reached:i>=25,label:"完成 25%"},{percentage:50,reached:i>=50,label:"完成 50%"},{percentage:75,reached:i>=75,label:"完成 75%"},{percentage:100,reached:i>=100,label:"完成 100%"}]}}(e):null,[e]),r=(0,s.useMemo)(()=>e?e?e.liabilityPlans.filter(e=>e.completionMonth>0&&-1!==e.completionMonth).map(e=>({liabilityId:e.liabilityId,liabilityName:e.liabilityName,completionMonth:e.completionMonth})):[]:[],[e]);return e?(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)(i.aR,{children:[(0,a.jsx)(i.ZB,{children:"還款提醒與進度"}),(0,a.jsx)(i.BT,{children:"追蹤還款進度和重要日期"})]}),(0,a.jsxs)(i.Wu,{className:"space-y-4",children:[t&&(0,a.jsxs)("div",{className:"flex items-center gap-3 p-3 border rounded-lg",children:[(0,a.jsx)(V.A,{className:"h-5 w-5 text-muted-foreground"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"下次還款日期"}),(0,a.jsx)("p",{className:"text-lg font-bold",children:(0,D.GP)(t,"yyyy 年 MM 月 dd 日")})]}),(0,a.jsxs)(Y.E,{variant:"outline",children:[Math.ceil((t.getTime()-new Date().getTime())/864e5)," 天後"]})]}),l&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"整體還款進度"}),(0,a.jsxs)("p",{className:"text-lg font-bold",children:[l.overallProgress.toFixed(1),"%"]})]}),(0,a.jsx)(J.k,{value:l.overallProgress,className:"h-2"}),(0,a.jsx)("div",{className:"grid grid-cols-4 gap-2 mt-3",children:l.milestones.map((e,t)=>(0,a.jsxs)("div",{className:`flex flex-col items-center p-2 rounded-lg border ${e.reached?"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800":"bg-muted"}`,children:[(0,a.jsx)(G.A,{className:`h-5 w-5 mb-1 ${e.reached?"text-green-600 dark:text-green-400":"text-muted-foreground"}`}),(0,a.jsx)("span",{className:"text-xs font-medium",children:e.label})]},t))})]}),r.length>0&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(X.A,{className:"h-4 w-4 text-green-600"}),(0,a.jsx)("p",{className:"text-sm font-medium",children:"已還清負債"})]}),(0,a.jsx)("div",{className:"space-y-1",children:r.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between p-2 bg-green-50 dark:bg-green-950 rounded-lg",children:[(0,a.jsx)("span",{className:"text-sm",children:e.liabilityName}),(0,a.jsxs)(Y.E,{variant:"outline",className:"bg-green-100 dark:bg-green-900",children:["第 ",e.completionMonth," 個月還清"]})]},e.liabilityId))})]})]})]}):null}function q({liabilities:e,userId:t,onLiabilityUpdate:l}){let{toast:r}=(0,u.dj)(),n=(0,s.useMemo)(()=>({async getDebtRepaymentPlan(e){try{if(!g.db)throw Error("Firestore 尚未初始化");if(!e)throw Error("用戶 ID 未提供");let t=(0,b.P)((0,b.rJ)(g.db,w),(0,b._M)("userId","==",e)),l=await (0,b.GG)(t);if(l.empty)return{ok:!0,data:void 0};
1let a=l.docs[0].data(),r={id:l.docs[0].id,...a};return P.parse(r),{ok:!0,data:r}}catch(e){return(0,A.vV)("取得償債計劃失敗:",e),{ok:!1,error:e?.message||"getDebtRepaymentPlan_failed"}}},async saveDebtRepaymentPlan(e){try{if(!g.db)throw Error("Firestore 尚未初始化");if(!e.userId)throw Error("用戶 ID 未提供");let t=await this.getDebtRepaymentPlan(e.userId);if(t.ok&&t.data)return await this.updateDebtRepaymentPlan(t.data.id,{monthlyBudget:e.monthlyBudget,strategy:e.strategy,liabilityAllocations:e.liabilityAllocations,updatedAt:new Date().toISOString()});let l=new Date().toISOString(),a=P.parse({...e,createdAt:l,updatedAt:l}),r=(0,b.doc)((0,b.rJ)(g.db,w));return await (0,b.setDoc)(r,a),{ok:!0,data:r.id}}catch(e){return(0,A.vV)("儲存償債計劃失敗:",e),{ok:!1,error:e?.message||"saveDebtRepaymentPlan_failed"}}},async updateDebtRepaymentPlan(e,t){try{if(!g.db)throw Error("Firestore 尚未初始化");if(!e)throw Error("計劃 ID 未提供");let l=(0,b.doc)(g.db,w,e),a=await (0,b.getDoc)(l);if(!a.exists())throw Error("償債計劃不存在");let r=new Date().toISOString(),n={...a.data(),...t,updatedAt:r};return P.parse(n),await (0,b.mZ)(l,n),{ok:!0}}catch(e){return(0,A.vV)("更新償債計劃失敗:",e),{ok:!1,error:e?.message||"updateDebtRepaymentPlan_failed"}}}}),[]),[f,v]=(0,s.useState)(""),[N,M]=(0,s.useState)("proportional"),[S,T]=(0,s.useState)([]),[F,$]=(0,s.useState)({}),[Z,O]=(0,s.useState)(!1),[W,Y]=(0,s.useState)(null),[J,V]=(0,s.useState)(!1),[G,X]=(0,s.useState)(!1),[z,U]=(0,s.useState)([]),K=(0,s.useMemo)(()=>e.reduce((e,t)=>{let l=t.minimumPayment||0;if(0===l||null==l){let a=t.annualRate,r=t.loanTerm??0,n=t.repaymentMethod||"equal-payment";if(null==a||""===a)return e;{let s=(0,p.A7)(t.value,t.currency);if(r>0)try{let e={loanAmount:s,annualRate:parseFloat(a.toString()),loanTerm:r,repaymentMethod:n,loanType:"personal-loan"};l=(0,j.OM)(e).monthlyPayment}catch(t){return console.error("計算最低還款額失敗:",t),e}else 0===r&&(l=s*(parseFloat(a.toString())/100/12))}}else l=(0,p.A7)(l,t.currency);return l>0?e+l:e},0),[e]);(0,s.useEffect)(()=>{t?(async()=>{let e=await n.getDebtRepaymentPlan(t);if(e.ok&&e.data){if(v(e.data.monthlyBudget.toString()),M(e.data.strategy.type),T(e.data.strategy.priorityOrder||[]),e.data.strategy.customAllocations){let t={};Object.entries(e.data.strategy.customAllocations).forEach(([e,l])=>{t[e]=l.toString()}),$(t)}O(!0)}else O(!0)})():O(!0)},[t,n]),(0,s.useEffect)(()=>{Z&&""===f&&K>0&&v(Math.round(K).toString())},[Z,f,K]);let Q=(0,s.useMemo)(()=>e.filter(e=>{let t=e.annualRate;return null==t||""===t}),[e]),ee=(0,s.useCallback)(async l=>{let a=!!l?.silent,s=parseFloat(f);if(!s||s<=0)if(K>0)s=K,v(Math.round(K).toString());else{a||r({title:"錯誤",description:"請輸入有效的每月還款預算,或為負債設定最低還款額",variant:"destructive"});return}V(!0);try{let l=e.filter(e=>{let t=e.annualRate;return!(0>=(Number(e.value)||0))&&null!=t&&""!==t}).map(e=>{let t=e.annualRate||0,l=e.loanTerm??0,a=e.repaymentMethod||"equal-payment",r=e.minimumPayment||0,n=r>0?(0,p.A7)(r,e.currency):0;if(n<=0){let r=(0,p.A7)(e.value,e.currency);if(l>0)try{let e={loanAmount:r,annualRate:Number(t)||0,loanTerm:Number(l)||0,repaymentMethod:a,loanType:"personal-loan"};n=(0,j.OM)(e).monthlyPayment}catch{n=0}else{let e=(Number(t)||0)/100/12;n=r*e}}return(0,y.oL)({...e,annualRate:t,loanTerm:l,repaymentMethod:a,minimumPayment:n,startDate:e.startDate},t,l,a)});if(0===l.length){a||r({title:"錯誤",description:"請至少有一個負債設定年利率。請先編輯負債以設定年利率。",variant:"destructive"}),V(!1);return}let i={type:N};if("priority"===N&&S.length>0&&(i.priorityOrder=S),"custom"===N){let e=Object.fromEntries(Object.entries(F).map(([e,t])=>[e,parseFloat(t)||0]));Object.keys(e).length>0&&(i.customAllocations=e)}let o={liabilities:l,monthlyBudget:s,strategy:i},c=(0,y.D0)(o);if(Y(c),U(l),t)try{await n.saveDebtRepaymentPlan({userId:t,monthlyBudget:s,strategy:i,liabilityAllocations:c.liabilityPlans.map(e=>({liabilityId:e.liabilityId,monthlyPayment:0}))})}catch(e){console.error("自動儲存計劃失敗:",e)}}catch(e){a?console.error("自動計算償債計劃失敗:",e):r({title:"計算失敗",description:e.message||"無法計算償債計劃",variant:"destructive"})}finally{V(!1)}},[e,f,N,S,F,K,r,n,t]),et=(0,s.useMemo)(()=>{let t="custom"===N?Object.entries(F).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${e}:${t}`).join("|"):"",l="priority"===N?S.join("|"):"";return["v1",f,N,l,t,e.map(e=>[e.id,e.value,e.currency,e.annualRate??"",e.loanTerm??"",e.repaymentMethod??"",e.minimumPayment??"",e.startDate??""].join(":")).join(";")].join("::")},[e,f,N,S,F]),el=(0,s.useRef)("");return(0,s.useEffect)(()=>{!Z||J||et!==el.current&&(el.current=et,ee({silent:!0}))},[et,Z,J,ee]),(0,s.useEffect)(()=>{"priority"===N&&0===S.length&&e.length>0&&T(e.map(e=>e.id))},[e,N,S.length]),(0,s.useCallback)(e=>{T(e)},[]),(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)(i.aR,{children:[(0,a.jsx)(i.ZB,{children:"償債計劃設定"}),(0,a.jsx)(i.BT,{children:"設定每月還款預算和還款策略"})]}),(0,a.jsxs)(i.Wu,{className:"space-y-4",children:[Q.length>0&&(0,a.jsxs)(C.Fc,{className:"mb-4",children:[(0,a.jsx)(R.A,{className:"h-4 w-4"}),(0,a.jsxs)(C.TN,{children:["有 ",Q.length," 個負債尚未設定年利率,請先",(0,a.jsx)(o.$,{variant:"link",className:"h-auto p-0 ml-1",onClick:()=>{r({title:"提示",description:"請在「負債清單」頁面編輯負債以設定年利率"})},children:"編輯負債"}),"設定年利率後再計算。"]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{htmlFor:"monthlyBudget",children:"每月還款總預算(TWD)"}),(0,a.jsx)(c.p,{id:"monthlyBudget",type:"number",value:f,onChange:e=>
1v(e.target.value),placeholder:"例如:50000(留空則使用所有負債的最低還款額總和)",min:"0",step:"1000"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"每月可用於還款的金額總和。系統會根據選擇的還款策略,將此預算分配給各個負債。 如果未輸入,將使用所有負債的最低還款額總和。"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{htmlFor:"strategy",children:"還款策略"}),(0,a.jsxs)(m.l6,{value:N,onValueChange:e=>M(e),children:[(0,a.jsx)(m.bq,{id:"strategy",children:(0,a.jsx)(m.yv,{})}),(0,a.jsxs)(m.gC,{children:[(0,a.jsx)(m.eb,{value:"proportional",children:"按比例分配"}),(0,a.jsx)(m.eb,{value:"priority",children:"優先順序"}),(0,a.jsx)(m.eb,{value:"high-interest",children:"高利率優先(雪球法)"}),(0,a.jsx)(m.eb,{value:"low-balance",children:"小額優先(滾雪球法)"}),(0,a.jsx)(m.eb,{value:"custom",children:"自訂分配"})]})]}),(0,a.jsxs)("p",{className:"text-xs text-muted-foreground",children:["proportional"===N&&"根據各負債餘額比例分配每月還款","priority"===N&&"按照設定的優先順序分配還款","high-interest"===N&&"優先還清高利率負債,可減少總利息支出","low-balance"===N&&"優先還清小額負債,可快速減少負債數量","custom"===N&&"手動設定每個負債的每月還款金額"]})]}),"priority"===N&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{children:"優先順序"}),(0,a.jsx)("div",{className:"space-y-2 border rounded-lg p-3 bg-muted/50",children:(S.length>0?S:e.map(e=>e.id)).map((t,l)=>{let r=e.find(e=>e.id===t);return r?(0,a.jsxs)("div",{className:"flex items-center gap-2 p-2 rounded bg-background",children:[(0,a.jsx)("span",{className:"text-sm text-muted-foreground w-6 text-center",children:l+1}),(0,a.jsx)("span",{className:"flex-1",children:r.name})]},t):null})}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"優先順序會按照負債列表的順序。如需調整,請在「負債清單」頁面重新排序負債。"})]}),"custom"===N&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.J,{children:"自訂分配"}),e.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(d.J,{className:"w-32",children:e.name}),(0,a.jsx)(c.p,{type:"number",value:F[e.id]||"",onChange:t=>$(l=>({...l,[e.id]:t.target.value})),placeholder:"每月還款金額",min:"0",step:"1000"})]},e.id))]}),(0,a.jsxs)(o.$,{onClick:()=>ee(),disabled:J,children:[(0,a.jsx)(I.A,{className:"h-4 w-4 mr-2"}),J?"計算中...":"重新計算"]})]})]}),(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsx)(_,{planResult:W}),(0,a.jsxs)(i.Zp,{children:[(0,a.jsx)(i.aR,{children:(0,a.jsx)(i.ZB,{children:"計劃摘要"})}),(0,a.jsx)(i.Wu,{children:(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"總負債餘額"}),(0,a.jsx)("p",{className:"text-2xl font-bold",children:W?(0,x.C)(W.summary.totalLiabilities):"—"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"每月還款"}),(0,a.jsx)("p",{className:"text-2xl font-bold",children:W?(0,x.C)(W.summary.averageMonthlyPayment):"—"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"總利息"}),(0,a.jsx)("p",{className:"text-2xl font-bold text-red-600",children:W?W.totalInterest===1/0?"持續計算中":(0,x.C)(W.totalInterest):"—"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"完成日期"}),(0,a.jsx)("p",{className:"text-2xl font-bold",children:W?W.liabilityPlans.some(e=>
1-1===e.completionMonth)?"無還款期限":(0,D.GP)(new Date(W.summary.completionDate),"yyyy/MM/dd"):"—"})]})]})})]}),(0,a.jsxs)(h.tU,{defaultValue:"summary",className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex justify-between items-center",children:[(0,a.jsx)("div",{className:"inline-flex",children:(0,a.jsxs)(h.j7,{children:[(0,a.jsx)(h.Xi,{value:"summary",children:"摘要表格"}),(0,a.jsx)(h.Xi,{value:"timeline",children:"明細"}),(0,a.jsx)(h.Xi,{value:"charts",children:"圖表"}),(0,a.jsx)(h.Xi,{value:"gantt",children:"甘特圖"})]})}),(0,a.jsxs)(o.$,{variant:"outline",onClick:()=>X(!G),className:"ml-4",disabled:!W,children:[(0,a.jsx)(B.A,{className:"h-4 w-4 mr-2"}),G?"隱藏比較":"比較方案"]})]}),W&&G&&z.length>0&&(0,a.jsx)(L,{liabilities:z,monthlyBudget:parseFloat(f)||0}),(0,a.jsx)(h.av,{value:"summary",children:(0,a.jsxs)(i.Zp,{children:[(0,a.jsx)(i.aR,{children:(0,a.jsx)(i.ZB,{children:"各負債還款摘要"})}),(0,a.jsx)(i.Wu,{children:W?(0,a.jsxs)(k.XI,{children:[(0,a.jsx)(k.A0,{children:(0,a.jsxs)(k.Hj,{children:[(0,a.jsx)(k.nd,{children:"負債名稱"}),(0,a.jsx)(k.nd,{className:"text-right",children:"完成月份"}),(0,a.jsx)(k.nd,{className:"text-right",children:"總利息"}),(0,a.jsx)(k.nd,{className:"text-right",children:"總還款"})]})}),(0,a.jsx)(k.BF,{children:W.liabilityPlans.map(e=>(0,a.jsxs)(k.Hj,{children:[(0,a.jsxs)(k.nA,{children:[e.liabilityName,-1===e.completionMonth&&(0,a.jsx)("span",{className:"ml-2 text-xs text-muted-foreground",children:"(無還款期限)"})]}),(0,a.jsx)(k.nA,{className:"text-right",children:-1===e.completionMonth?"無還款期限":e.completionMonth}),(0,a.jsx)(k.nA,{className:"text-right",children:e.totalInterest===1/0?"持續計算中":(0,x.C)(e.totalInterest)}),(0,a.jsx)(k.nA,{className:"text-right",children:e.totalPayment===1/0?"持續計算中":(0,x.C)(e.totalPayment)})]},e.liabilityId))})]}):(0,a.jsx)("p",{className:"text-center text-muted-foreground py-8",children:"尚無計劃資料(會在載入後自動計算)"})})]})}),(0,a.jsx)(h.av,{value:"timeline",children:(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)(i.aR,{children:[(0,a.jsx)(i.ZB,{children:"還款明細"}),(0,a.jsx)(i.BT,{children:"每月還款詳細資料"})]}),(0,a.jsx)(i.Wu,{children:W?(0,a.jsx)("div",{className:"max-h-[600px] overflow-auto",children:(0,a.jsxs)(k.XI,{children:[(0,a.jsx)(k.A0,{children:(0,a.jsxs)(k.Hj,{children:[(0,a.jsx)(k.nd,{children:"月份"}),(0,a.jsx)(k.nd,{children:"日期"}),(0,a.jsx)(k.nd,{className:"text-right",children:"總還款"}),(0,a.jsx)(k.nd,{className:"text-right",children:"本金"}),(0,a.jsx)(k.nd,{className:"text-right",children:"利息"})]})}),(0,a.jsx)(k.BF,{children:W.monthlyDetails.map(e=>(0,a.jsxs)(k.Hj,{children:[(0,a.jsx)(k.nA,{children:e.month}),(0,a.jsx)(k.nA,{children:(0,D.GP)(new Date(e.date),"yyyy/MM/dd")}),(0,a.jsx)(k.nA,{className:"text-right",children:(0,x.C)(e.totalPayment)}),(0,a.jsx)(k.nA,{className:"text-right",children:(0,x.C)(e.totalPrincipal)}),(0,a.jsx)(k.nA,{className:"text-right",children:(0,x.C)(e.totalInterest)})]},e.month))})]})}):(0,a.jsx)("p",{className:"text-center text-muted-foreground py-8",children:"尚無計劃資料(會在載入後自動計算)"})})]})}),(0,a.jsx)(h.av,{value:"charts",children:(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)(i.aR,{children:[(0,a.jsx)(i.ZB,{children:"還款進度圖"}),(0,a.jsx)(i.BT,{children:"各負債剩餘本金變化趨勢"})]}),(0,a.jsx)(i.Wu,{children:W?(0,a.jsx)(E,{planResult:W}):(0,a.jsx)("p",{className:"text-center text-muted-foreground py-8",children:"尚無計劃資料(會在載入後自動計算)"})})]})}),(0,a.jsx)(h.av,{value:"gantt",children:(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)(i.aR,{children:[(0,a.jsx)(i.ZB,{children:"還款時間軸"}),(0,a.jsx)(i.BT,{children:"各負債的還款時間軸視覺化"})]}),(0,a.jsx)(i.Wu,{children:W?(0,a.jsx)(H,{planResult:W}):(0,a.jsx)("p",{className:"text-center text-muted-foreground py-8",children:"尚無計劃資料(會在載入後自動計算)"})})]})})]})]})]})}function z(){let{user:e,viewingUserId:t}=(0,r.A)(),l=t||e?.uid||"",{liabilities:s,updateLiability:i,loading:o}=(0,n.d)(l||void 0);return l?o?(0,a.jsx)("div",{className:"rounded-lg border p-10 text-center text-sm text-muted-foreground",children:"載入中…"}):(0,a.jsx)(q,{liabilities:s,userId:l,onLiabilityUpdate:async(e,t)=>{await i(e,t)}}):(0,a.jsx)("div",{className:"rounded-lg border border-dashed p-10 text-center text-sm text-muted-foreground",children:"請先登入"})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.