"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[752],{53752:function(e,t,n){n.d(t,{FinancialProvider:function(){return l},O:function(){return d}});var r=n(57437),a=n(2265),o=n(565),i=n(7795),c=n(51487);let s={current_config:null,saved_configs:[],current_quarter:1,current_view_date:{year:2025,month:1},view_mode:"monthly",comparison_mode:"none",is_loading:!1,error_message:null,chart_data:{debt_paydown:[],cash_flow:[],net_worth:[],income_allocation:[],investment_growth:[],asset_allocation:[],amortization:[],interest_analysis:[],budget_variance:[]},historical_data_loaded:!1,actual_data_available:{},features:{calendar_view_enabled:!0,investment_tracking_enabled:!0,asset_tracking_enabled:!0,amortization_enabled:!0,variance_analysis_enabled:!0}};function _(e,t){switch(t.type){case"LOAD_CONFIG":return{...e,current_config:t.payload,is_loading:!1,error_message:null};case"SAVE_CONFIG":let n=e.saved_configs.filter(e=>e.id!==t.payload.id);return n.push(t.payload),{...e,current_config:t.payload,saved_configs:n,error_message:null};case"UPDATE_FINANCIAL_DATA":if(!e.current_config)return e;let r={...e.current_config,data:{...e.current_config.data,...t.payload},last_modified:new Date().toISOString()};return{...e,current_config:r};case"SET_QUARTER":return{...e,current_quarter:t.payload};case"SET_LOADING":return{...e,is_loading:t.payload};case"SET_ERROR":return{...e,error_message:t.payload,is_loading:!1};case"UPDATE_CHART_DATA":return{...e,chart_data:{...e.chart_data,...t.payload}};case"ADD_DEBT_ACCOUNT":if(!e.current_config)return e;let a={...e.current_config,data:{...e.current_config.data,debt_accounts:[...e.current_config.data.debt_accounts,t.payload]}};return{...e,current_config:a};case"REMOVE_DEBT_ACCOUNT":if(!e.current_config)return e;let o={...e.current_config,data:{...e.current_config.data,debt_accounts:e.current_config.data.debt_accounts.filter(e=>e.id!==t.payload)}};return{...e,current_config:o};case"ADD_INCOME_SOURCE":if(!e.current_config)return e;let i={...e.current_config,data:{...e.current_config.data,income_sources:[...e.current_config.data.income_sources,t.payload]}};return{...e,current_config:i};case"REMOVE_INCOME_SOURCE":if(!e.current_config)return e;let c={...e.current_config,data:{...e.current_config.data,income_sources:e.current_config.data.income_sources.filter(e=>e.id!==t.payload)}};return{...e,current_config:c};case"ADD_EXPENSE_CATEGORY":if(!e.current_config)return e;let s={...e.current_config,data:{...e.current_config.data,expense_categories:[...e.current_config.data.expense_categories,t.payload]}};return{...e,current_config:s};case"REMOVE_EXPENSE_CATEGORY":if(!e.current_config)return e;let _={...e.current_config,data:{...e.current_config.data,expense_categories:e.current_config.data.expense_categories.filter(e=>e.id!==t.payload)}};return{...e,current_config:_};case"ADD_INVESTMENT_ACCOUNT":if(!e.current_config)return e;let u={...e.current_config,data:{...e.current_config.data,investment_accounts:[...e.current_config.data.investment_accounts,t.payload]}};return{...e,current_config:u};case"REMOVE_INVESTMENT_ACCOUNT":if(!e.current_config)return e;let l={...e.current_config,data:{...e.current_config.data,investment_accounts:e.current_config.data.investment_accounts.filter(e=>e.id!==t.payload)}};return{...e,current_config:l};case"ADD_ASSET":if(!e.current_config)return e;let d={...e.current_config,data:{...e.current_config.data,assets:[...e.current_config.data.assets,t.payload]}};return{...e,current_config:d};case"REMOVE_ASSET":if(!e.current_config)return e;let m={...e.current_config,data:{...e.current_config.data,assets:e.current_config.data.assets.filter(e=>e.id!==t.payload)}};return{...e,current_config:m};default:return e}}let u=(0,a.createContext)(null);function l({children:e}){let[t,n]=(0,a.useReducer)(_,s),l=a.useMemo(()=>{if(!t.current_config?.data)return[];try{return(0,o.WE)(t.current_config.data)}catch(e){return console.error("Error generating projections:",e),[]}},[t.current_config?.data?.debt_accounts,t.current_config?.data?.income_sources,t.current_config?.data?.expense_categories,t.current_config?.data?.investment_accounts,t.current_config?.data?.assets,t.current_config?.data?.housing,t.current_config?.data?.cash,t.current_config?.data?.payment_matrix,t.current_config?.data?.home_purchase_month,t.current_config?.data?.current_date,t.current_config?.data?.planning_horizon_months]),d=a.useMemo(()=>{if(!t.current_config?.data||0===l.length)return null;try{return(0,o.Qt)(t.current_config.data,l,t.current_quarter)}catch(e){return console.error("Error calculating KPIs:",e),null}},[t.current_config?.data,l,t.current_quarter]);return(0,a.useEffect)(()=>{console.log("\uD83D\uDD04 Financial context initializing..."),n({type:"SET_LOADING",payload:!0});try{let e=null,t=[];if(console.log("\uD83C\uDF10 Browser environment detected, checking localStorage..."),e=(0,i.pK)(),t=(0,i.pH)(),console.log("\uD83D\uDCE6 Loaded from localStorage:",{hasCurrentConfig:!!e,savedConfigsCount:t.length}),e)console.log("✅ Loading existing configuration:",e.name),n({type:"LOAD_CONFIG",payload:e});else{console.log("\uD83C\uDD95 Creating default configuration...");let e=(0,c.EF)();console.log("\uD83D\uDCCA Generated default data:",{incomeSourcesCount:e.income_sources?.length||0,debtAccountsCount:e.debt_accounts?.length||0,expenseCategoriesCount:e.expense_categories?.length||0});let t=(0,c.eD)("Default Budget","Initial budget configuration",e);console.log("\uD83C\uDFAF Created default configuration:",t.id),n({type:"LOAD_CONFIG",payload:t});try{(0,i.VH)(t),console.log("\uD83D\uDCBE Saved default configuration to localStorage")}catch(e){console.warn("Could not save default configuration to localStorage:",e)}}t.forEach(e=>{n({type:"SAVE_CONFIG",payload:e})}),n({type:"SET_LOADING",payload:!1})}catch(e){console.error("Error loading initial data:",e),n({type:"LOAD_CONFIG",payload:(0,c.eD)("Default Budget","Initial budget configuration",(0,c.EF)())}),n({type:"SET_ERROR",payload:"Using default configuration due to loading error"}),n({type:"SET_LOADING",payload:!1})}},[]),(0,a.useEffect)(()=>{if(0!==l.length)try{let e={debt_paydown:l.map(e=>({label:`Month ${e?.month||0}`,value:e?.total_debt_balance||0,month:e?.month||0})),cash_flow:l.map(e=>({label:`Month ${e?.month||0}`,value:e?.surplus||0,month:e?.month||0})),net_worth:l.map(e=>({label:`Month ${e?.month||0}`,value:(e?.cash_balance||0)-(e?.total_debt_balance||0),month:e?.month||0})),income_allocation:(t.current_config?.data?.income_sources||[]).map(e=>({label:e?.name||"Unknown Source",value:e?.base_amount||0,category:e?.type||"other"}))};n({type:"UPDATE_CHART_DATA",payload:e})}catch(e){console.error("Error generating chart data:",e)}},[l,t.current_config?.data]),(0,r.jsx)(u.Provider,{value:{state:t,dispatch:n,projections:l,kpis:d,updateFinancialData:e=>{n({type:"UPDATE_FINANCIAL_DATA",payload:e})},createNewConfig:(e,t)=>{n({type:"LOAD_CONFIG",payload:(0,c.eD)(e,t)})},loadConfig:e=>{n({type:"LOAD_CONFIG",payload:e})},saveCurrentConfig:()=>{if(t.current_config)try{(0,i.VH)(t.current_config),n({type:"SAVE_CONFIG",payload:t.current_config})}catch(e){console.error("Error saving configuration:",e),n({type:"SET_ERROR",payload:"Failed to save configuration"})}},autoSave:()=>{if(t.current_config)try{(0,i.$)(t.current_config)}catch(e){console.error("Error auto-saving configuration:",e)}}},children:e})}function d(){let e=(0,a.useContext)(u);if(!e)throw Error("useFinancial must be used within a FinancialProvider");return e}},51487:function(e,t,n){function r(){return{income_sources:[{id:"income_1",name:"Primary Salary",base_amount:8000.64,gross_amount:11112,net_amount:8000.64,type:"salary",tax_rate:28,start_date:{year:2024,month:1},schedule_changes:[]},{id:"income_2",name:"Side Business",base_amount:1e3,gross_amount:1e3,net_amount:850,type:"business",tax_rate:15,start_date:{year:2024,month:3},schedule_changes:[]}],debt_accounts:[{id:"debt_1",name:"Student Loan",balance:25e3,original_balance:3e4,min_payment:300,apr:6.25,type:"student_loan",total_interest_paid:2500},{id:"debt_2",name:"Credit Card",balance:5e3,original_balance:12e3,min_payment:200,apr:0,type:"credit_card",total_interest_paid:1200},{id:"debt_3",name:"Car Loan",balance:3500,original_balance:22e3,min_payment:225,apr:3,type:"car_payment",total_interest_paid:1800},{id:"debt_4",name:"Personal Loan",balance:39500,original_balance:39500,min_payment:975,apr:14.49,type:"personal_loan",total_interest_paid:0,start_date:{year:2024,month:1}}],expense_categories:[{id:"expense_1",name:"Groceries",base_amount:1e3,type:"variable",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_2",name:"Utilities",base_amount:500,type:"fixed",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_3",name:"Gas",base_amount:250,type:"variable",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_4",name:"Car Insurance",base_amount:120,type:"fixed",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_5",name:"Subscriptions",base_amount:80,type:"fixed",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_6",name:"Entertainment",base_amount:200,type:"discretionary",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_7",name:"Shopping",base_amount:200,type:"discretionary",start_date:{year:2024,month:1},schedule_changes:[]},{id:"expense_8",name:"Savings",base_amount:500,type:"fixed",start_date:{year:2024,month:1},schedule_changes:[]}],investment_accounts:[{id:"investment_1",name:"401(k)",type:"401k",current_value:2e4,monthly_contribution:200,employer_match:165,annual_return_rate:9,risk_level:"medium",start_date:{year:2020,month:1}},{id:"investment_2",name:"Roth IRA",type:"roth_ira",current_value:2e3,monthly_contribution:0,annual_return_rate:8,risk_level:"medium",start_date:{year:2022,month:1}},{id:"investment_4",name:"Crypto",type:"other",current_value:7500,monthly_contribution:0,annual_return_rate:5,risk_level:"medium",start_date:{year:2023,month:8},precious_metals:[{id:"gold_1",type:"gold",ounces_owned:5,current_price_per_ounce:2100,total_value:10500,last_updated:{year:2025,month:1}},{id:"silver_1",type:"silver",ounces_owned:50,current_price_per_ounce:30,total_value:1500,last_updated:{year:2025,month:1}}]}],assets:[],housing:{home_price:485e3,down_pct:10,interest_rate:6.25,property_tax_rate:1.2,insurance_monthly:150,pmi_rate:.5,hoa_monthly:0,maintenance_pct:1,loan_term:30},cash:{initial_cash:1e5,closing_cost_pct_price:2.5,closing_cost_pct_loan:1,escrow_months:3,current_rent:2e3,emergency_fund_months:6},payment_matrix:{payments:{debt_1:Array(24).fill(0),debt_2:[100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100],debt_3:Array(24).fill(25),debt_4:Array(24).fill(0)},receipts:Array(24).fill(0),lump_sum_expenses:[],lump_sum_receipts:[]},home_purchase_month:1,current_date:{year:2025,month:1},planning_horizon_months:24,historical_entries:[],settings:{default_tax_rate:25,inflation_rate:3,emergency_fund_target_months:6,debt_avalanche_enabled:!0,auto_save_enabled:!0}}}function a(){return{id:`debt_${Date.now()}_${Math.random().toString(36).substr(2,5)}`,name:"",balance:0,min_payment:0,apr:0,type:"other",start_date:{year:new Date().getFullYear(),month:new Date().getMonth()+1},total_interest_paid:0}}function o(){return{id:`income_${Date.now()}_${Math.random().toString(36).substr(2,5)}`,name:"",base_amount:0,gross_amount:0,net_amount:0,type:"other",tax_rate:25,start_date:{year:new Date().getFullYear(),month:new Date().getMonth()+1},schedule_changes:[]}}function i(){return{id:`expense_${Date.now()}_${Math.random().toString(36).substr(2,5)}`,name:"",base_amount:0,type:"variable",start_date:{year:new Date().getFullYear(),month:new Date().getMonth()+1},schedule_changes:[]}}function c(){return{id:`investment_${Date.now()}_${Math.random().toString(36).substr(2,5)}`,name:"",type:"savings",current_value:0,monthly_contribution:0,annual_return_rate:5,risk_level:"medium",start_date:{year:new Date().getFullYear(),month:new Date().getMonth()+1}}}function s(){return{id:`asset_${Date.now()}_${Math.random().toString(36).substr(2,5)}`,name:"",type:"other",current_value:0,purchase_date:{year:new Date().getFullYear(),month:new Date().getMonth()+1}}}function _(){return`config_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function u(e,t,n){let a=new Date().toISOString();return{id:_(),name:e,description:t,created_date:a,last_modified:a,version:"2.0.0",data:{...r(),...n},metadata:{scenario_type:"base",created_by:"user",last_calculated:a}}}n.d(t,{EF:function(){return r},JV:function(){return o},WS:function(){return a},eD:function(){return u},mE:function(){return i},ng:function(){return s},rm:function(){return c},tT:function(){return _}})},565:function(e,t,n){function r(e,t){let n=e.year,r=e.month+t;for(;r>12;)r-=12,n+=1;for(;r<1;)r+=12,n-=1;return{year:n,month:r}}function a(e,t,n){let r=e;for(let e of t.sort((e,t)=>e.date.year!==t.date.year?e.date.year-t.date.year:e.date.month-t.date.month))if(e.date.yeart&&"object"==typeof t?e+(t.current_price||0)*(t.shares_owned||0):e,0):0}function c(e){return e&&Array.isArray(e)?e.reduce((e,t)=>t&&"object"==typeof t?e+(t.total_value||0):e,0):0}function s(e,t){if(!e||!Array.isArray(e))return{gross:0,net:0,breakdown:{}};let n=0,r=0,o={};return e.forEach(e=>{if(!e||"object"!=typeof e)return;let i=a(e.gross_amount||e.base_amount||0,e.schedule_changes||[],t),c=a(e.net_amount||e.base_amount||0,e.schedule_changes||[],t);n+=i,r+=c,o[e.id]=c}),{gross:n,net:r,breakdown:o}}function _(e,t){if(!e||!Array.isArray(e))return{total:0,breakdown:{}};let n=0,r={};return e.forEach(e=>{if(!e||"object"!=typeof e)return;let o=a(e.base_amount||0,e.schedule_changes||[],t);n+=o,r[e.id]=o}),{total:n,breakdown:r}}function u(e){if(!e||e.length<2)return"stable";let t=e.slice(-3);if(t.length<2)return"stable";let n=t[t.length-1]-t[0],r=.05*Math.abs(t[0]);return n>r?"increasing":n<-r?"decreasing":"stable"}function l(e,t){if(!e||!Array.isArray(e))return{totalInterest:0,totalMonths:0,schedule:[]};let n=[...e].filter(e=>e&&(e.balance||0)>0).sort((e,t)=>(t.apr||0)-(e.apr||0)),r=0,a=0,o=n.map(e=>e.balance||0),i=t;for(;o.some(e=>e>.01)&&a<360;){a++;let e=0;n.forEach((t,n)=>{if(o[n]<=.01)return;let a=o[n]*((t.apr||0)/100/12),c=t.min_payment||0,s=i-e;if(0===n&&s>0){let t=Math.min(s,o[n]-a);c+=t,e+=t}let _=Math.min(c-a,o[n]);o[n]-=_,r+=a}),i=t}return{totalInterest:r,totalMonths:a,schedule:[]}}function d(e,t){let n=e.home_price*(1-e.down_pct/100),r=o(n,e.interest_rate,e.loan_term),a=e.home_price*e.property_tax_rate/100/12,i=e.insurance_monthly,c=e.down_pct<20?n*e.pmi_rate/100/12:0,s=e.hoa_monthly,_=e.home_price*e.maintenance_pct/100/12;return{pi:r,tax:a,insurance:i,pmi:c,hoa:s,maintenance:_,total:r+a+i+c+s+_}}function m(e,t){var n;if(!e.purchase_date)return e.current_value;let r=(n=e.purchase_date,(t.year-n.year)*12+(t.month-n.month));if(r<=0)return e.current_value;let a=e.current_value,o=(e.appreciation_rate||e.depreciation_rate||0)/100/12;return e.appreciation_rate?a=e.current_value*Math.pow(1+o,r):e.depreciation_rate&&(a=e.current_value*Math.pow(1-o,r)),Math.max(0,a)}function p(e,t,n=24){let r={};if(!Array.isArray(e))return r;let a=t||{};return e.forEach(e=>{if(!e)return;r[e.id]=[];let t=e.balance||0,o=0,i=0;for(let c=0;c0?t/e*100:0,backEnd:e>0?(t+n)/e*100:0}}function g(e,t){let n=12*e;return n>0?t/n:0}function f(e,t,n){return{frontEnd:e>0?t/e*100:0,backEnd:e>0?(t+n)/e*100:0}}function y(e){let t=[];if(!e||"object"!=typeof e)return t;let n=e.planning_horizon_months||24,a={...e,debt_accounts:e.debt_accounts||[],income_sources:e.income_sources||[],expense_categories:e.expense_categories||[],investment_accounts:e.investment_accounts||[],assets:e.assets||[],current_date:e.current_date||{year:2025,month:1},payment_matrix:e.payment_matrix||{payments:{},receipts:[],lump_sum_expenses:[],lump_sum_receipts:[]},housing:e.housing||{home_price:0,down_pct:20,interest_rate:7,property_tax_rate:1.2,insurance_monthly:0,pmi_rate:.5,hoa_monthly:0,maintenance_pct:1,loan_term:30},cash:e.cash||{initial_cash:0,closing_cost_pct_price:2.5,closing_cost_pct_loan:1,escrow_months:3,current_rent:0,emergency_fund_months:6}},u=p(a.debt_accounts,a.payment_matrix.payments,n),l=function(e,t,n){let r={};return e&&Array.isArray(e)&&e.forEach(e=>{if(!e||"object"!=typeof e)return;r[e.id]=[];let t=e.current_value||0;e.ticker_symbols&&(t+=i(e.ticker_symbols)),e.precious_metals&&(t+=c(e.precious_metals));for(let a=0;ae.name?.toLowerCase().includes("savings")).reduce((e,t)=>e+(t.base_amount||0),0);let v=(a.home_purchase_month||7)-1,E=(a.housing?.home_price?a.housing.home_price*((a.housing.down_pct||20)/100):0)+(a.housing?.home_price?a.housing.home_price*((a.cash?.closing_cost_pct_price||2.5)/100):0),w=!1;for(let e=0;e=v;e===v&&a.housing?.home_price&&!w&&(d-=E,w=!0);let c=s(a.income_sources,n),p=_(a.expense_categories,n),A=function(e,t){return e&&Array.isArray(e)?e.reduce((e,n)=>{if(!n||"object"!=typeof n)return e;let r=n.date;return r?.year===t.year&&r?.month===t.month?e+(n.amount||0):e},0):0}(a.payment_matrix.lump_sum_expenses,n),D=function(e=[],t){return e.filter(e=>e.date.year===t.year&&e.date.month===t.month).reduce((e,t)=>e+(t.amount||0),0)}(a.payment_matrix.lump_sum_receipts,n)+(Array.isArray(a.payment_matrix.receipts)&&a.payment_matrix.receipts.length>e&&a.payment_matrix.receipts[e]||0),S=i?(()=>{let e=a.housing.home_price*(1-a.housing.down_pct/100),t=o(e,a.housing.interest_rate,a.housing.loan_term),n=a.housing.home_price*a.housing.property_tax_rate/100/12,r=a.housing.insurance_monthly;return t+n+r+(a.housing.down_pct<20?e*a.housing.pmi_rate/100/12:0)+(a.housing.hoa_monthly||0)+a.housing.home_price*a.housing.maintenance_pct/100/12})():a.cash.current_rent,C=i?{principal:.3*o(a.housing.home_price*(1-a.housing.down_pct/100),a.housing.interest_rate,a.housing.loan_term),interest:.7*o(a.housing.home_price*(1-a.housing.down_pct/100),a.housing.interest_rate,a.housing.loan_term),taxes:a.housing.home_price*(a.housing.property_tax_rate/100)/12,insurance:a.housing.insurance_monthly,hoa:a.housing.hoa_monthly||0,maintenance:a.housing.home_price*(a.housing.maintenance_pct/100)/12,pmi:a.housing.down_pct<20?a.housing.home_price*(1-a.housing.down_pct/100)*a.housing.pmi_rate/100/12:0}:{rent:a.cash.current_rent,taxes:0,insurance:0,maintenance:0,hoa:0,pmi:0},O=0,I=0,N={},F=0;a.debt_accounts.forEach(t=>{if(!t||"object"!=typeof t)return;let n=u[t.id];if(n&&n[e]){let r=n[e].balance,a=n[e].payment,o=n[e].interest,i=n[e].principal;O+=a,I+=r,y+=o,F+=o,N[t.id]={payment:a,principal:i,interest:o,balance:r}}});let k={},T=0;a.investment_accounts.forEach(t=>{if(!t)return;let n=l[t.id]?.[e]??(t.current_value||0);k[t.id]=n,T+=n});let R=a.investment_accounts.reduce((e,t)=>e+(t?.monthly_contribution||0),0),M=Object.values(a.payment_matrix.payments||{}).reduce((t,n)=>Array.isArray(n)&&n.length>e?t+(n[e]||0):t,0),j=Math.max(0,O-M),U=S+O+p.total+R+A,G=c.net+D-U,L=c.net-(S+O+p.total);d+=G;let $=i&&C.maintenance||0;b+=$;let V={original_plus_surplus:a.cash.initial_cash+G*(x=e+1),surplus_only:G*x,monthly_maintenance_aggregate:$*x},P=U>0?d/U:0;t.push({month:e+1,date:n,gross_income:c.gross,net_income:c.net,income_breakdown:c.breakdown,total_expenses:S+O+p.total+A,expense_breakdown:p.breakdown,housing_payment:S,housing_breakdown:C,housing_payment_type:i?"mortgage":"rent",debt_payments:O,required_debt_payments:j,debt_breakdown:N,total_debt_balance:I,total_interest_paid:y,monthly_interest:F,investment_contributions:R,investment_values:k,total_investment_value:T,asset_values:a.assets.reduce((e,t)=>{let r=m(t,n);return e[t.id]=r,e},{}),total_asset_value:a.assets.reduce((e,t)=>e+m(t,n),0),cash_balance:d,maintenance_fund_balance:b,net_invested_assets:T+b+a.assets.reduce((e,t)=>e+m(t,n),0),surplus:G,nominal_surplus:L,cash_flow_breakdown:V,debt_to_income_ratio:h(c.gross,S,j).backEnd,debt_to_income_ratio_net:f(c.net,S,j).backEnd,loan_to_income_ratio:g(c.gross,I),front_end_dti:h(c.gross,S,j).frontEnd,back_end_dti:h(c.gross,S,j).backEnd,front_end_dti_net:f(c.net,S,j).frontEnd,back_end_dti_net:f(c.net,S,j).backEnd,savings_rate:c.gross>0?(G+R)/c.gross*100:0,is_post_purchase:i,lump_sum_expenses:A,lump_sum_receipts:D,emergency_fund_months:P})}let A=(t[0]?.cash_balance||0)-E;return a.cash.initial_cash,a.housing?.home_price,a.housing?.is_purchase&&t.length>0&&(t[0].cash_balance=A),t}function b(e,t,n){if(!e||"object"!=typeof e||!t||!Array.isArray(t)||0===t.length)return{total_net_income:0,total_gross_income:0,monthly_net_income:0,monthly_gross_income:0,debt_to_income_ratio:0,debt_to_income_ratio_net:0,net_worth:0,total_monthly_expenses:0,monthly_housing_payment:0,monthly_debt_payments:0,monthly_other_expenses:0,housing_payment_type:"rent",front_end_dti:0,front_end_dti_net:0,home_affordability:0,housing_payment_ratio:0,down_payment:0,closing_costs:0,cash_to_close:0,cash_after_purchase:0,cash_after_close:0,monthly_minimum_payment:0,total_debt:0,debt_payoff_months:0,total_interest_remaining:0,debt_avalanche_savings:0,monthly_interest:0,monthly_surplus:0,quarterly_surplus:0,annual_surplus_projection:0,nominal_surplus:0,investment_contributions:0,savings_rate:0,loan_to_income_ratio:0,monthly_lump_sum_expenses:0,total_investments:0,investment_growth_rate:0,retirement_readiness_score:0,total_assets:0,asset_allocation:{},emergency_fund_months:0,emergency_fund_adequacy:"insufficient",financial_health_score:0,debt_freedom_date:{year:2025,month:1},retirement_goal_progress:0,emergency_fund_target_progress:0,total_interest_paid_ytd:0,total_interest_saved_ytd:0,interest_optimization_potential:0,precious_metals_value:0,ticker_portfolio_value:0,lump_sum_expenses_upcoming:0,budget_vs_actual_variance:0,trend_analysis:{income_trend:"stable",expense_trend:"stable",surplus_trend:"stable"}};let a=e.current_date||{year:2025,month:1},o=s(e.income_sources||[],a),d=_(e.expense_categories||[],a),p=e.debt_accounts||[],y=e.investment_accounts||[],b=e.assets||[],v=e.payment_matrix||{payments:{},receipts:[],lump_sum_expenses:[],lump_sum_receipts:[]},E=12*o.net,w=12*o.gross,x=o.net,A=o.gross,D=t[0]?.housing_payment||0,S=t[0]?.housing_payment_type||"rent",C=p.reduce((e,t)=>e+(t?.min_payment||0),0),O=Object.values(v.payments||{}).reduce((e,t)=>Array.isArray(t)&&t.length>0?e+(t[0]||0):e,0),I=C+O,N=d.total,F=D+I+N,k=y.reduce((e,t)=>e+(t?.monthly_contribution||0),0),T=t[0]?.lump_sum_expenses||0,R=x-(D+I+d.total+k+T),M=x-(D+I+d.total),j=p.reduce((e,t)=>e+(t?.balance||0),0),U=l(p,0),G=U.totalMonths,L=U.totalInterest,$=t[0]?Object.values(t[0].debt_breakdown).reduce((e,t)=>e+t.interest,0):0,V=function(e,t){if(!e||!Array.isArray(e)||t<=0)return{savings:0,optimalStrategy:"None",monthsSaved:0};let n=l(e,0),r=l(e,t);return{savings:n.totalInterest-r.totalInterest,optimalStrategy:"Debt Avalanche",monthsSaved:n.totalMonths-r.totalMonths}}(p,t[0]?.surplus||0),P=Math.max(0,I-O),J=h(o.gross,D,P),q=f(o.net,D,P),z=o.gross>0?D/o.gross*100:0,B=e.housing?.home_price?e.housing.home_price*((e.housing.down_pct||20)/100):0,H=e.housing?.home_price?e.housing.home_price*((e.cash?.closing_cost_pct_price||2.5)/100):0,Y=B+H,K=(t[0]?.cash_balance||0)-Y,Q=e.cash.initial_cash-(e.housing?.home_price?Y:0),W=t.slice(0,12).reduce((e,t)=>e+(t?.surplus||0),0),X=t.slice(0,3).reduce((e,t)=>e+(t?.surplus||0),0),Z=y.reduce((e,t)=>e+(t?.current_value||0),0),ee=y.reduce((e,t)=>e+(t?.monthly_contribution||0)+(t?.employer_match||0),0),et=y.reduce((e,t)=>t?.ticker_symbols?e+i(t.ticker_symbols):e,0),en=y.reduce((e,t)=>t?.precious_metals?e+c(t.precious_metals):e,0),er=b.reduce((e,t)=>e+m(t,a),0),ea=function(e,t,n=3){if(!e||!Array.isArray(e))return 0;let a=r(t,n);return e.reduce((e,n)=>{if(!n||"object"!=typeof n)return e;let r=n.date;return r&&(r.year>t.year||r.year===t.year&&r.month>=t.month)&&(r.year0?(t[0]?.cash_balance||0)/ec:0,e_=0;R>0&&(e_+=20),J.backEnd<36&&(e_+=20),es>=6&&(e_+=20),ei>0&&(e_+=20),(R+ee)/o.gross>.1&&(e_+=20);let eu=G>0?r(a,G):a,el=t.slice(0,6).map(e=>e.surplus||0),ed=t.slice(0,6).map(e=>e.net_income||0),em=t.slice(0,6).map(e=>e.total_expenses||0),ep=u(el),eh={income_trend:u(ed),expense_trend:u(em),surplus_trend:"increasing"===ep?"improving":"decreasing"===ep?"declining":"stable"},eg={};y.forEach(e=>{e?.type&&(eg[e.type]=(eg[e.type]||0)+(e.current_value||0))}),b.forEach(e=>{if(e?.type){let t=m(e,a);eg[e.type]=(eg[e.type]||0)+t}});let ef=y.length>0?y.reduce((e,t)=>e+(t?.annual_return_rate||0),0)/y.length:0,ey=Math.min(100,Z/(120*o.gross)*100);return{total_net_income:E,total_gross_income:w,monthly_net_income:x,monthly_gross_income:A,debt_to_income_ratio:J.backEnd,debt_to_income_ratio_net:q.backEnd,net_worth:ei,total_monthly_expenses:F,monthly_housing_payment:D,housing_payment_type:S,monthly_debt_payments:I,monthly_other_expenses:N,front_end_dti:J.frontEnd,front_end_dti_net:q.frontEnd,home_affordability:z,housing_payment_ratio:z,down_payment:B,closing_costs:H,cash_to_close:Y,cash_after_purchase:K,cash_after_close:Q,monthly_minimum_payment:C,total_debt:j,debt_payoff_months:G,total_interest_remaining:L,debt_avalanche_savings:V.savings,monthly_interest:$,monthly_surplus:R,quarterly_surplus:X,annual_surplus_projection:W,nominal_surplus:M,investment_contributions:k,savings_rate:o.gross>0?(R+k)/o.gross*100:0,loan_to_income_ratio:g(o.gross,j),monthly_lump_sum_expenses:T,total_investments:Z,investment_growth_rate:ef,retirement_readiness_score:ey,total_assets:er,asset_allocation:eg,emergency_fund_months:es,emergency_fund_adequacy:es>=6?"excellent":es>=3?"adequate":"insufficient",financial_health_score:e_,debt_freedom_date:eu,retirement_goal_progress:ey,emergency_fund_target_progress:es/6*100,total_interest_paid_ytd:t.slice(0,12).reduce((e,t)=>e+(t?.total_interest_paid||0),0),total_interest_saved_ytd:V.savings,interest_optimization_potential:V.savings,precious_metals_value:en,ticker_portfolio_value:et,lump_sum_expenses_upcoming:ea,budget_vs_actual_variance:0,trend_analysis:eh}}function v(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(e)}function E(e,t=1){return`${e.toFixed(t)}%`}function w(e,t){switch(t){case"surplus":return e>0?"text-green-600":"text-red-600";case"dti":if(e<28)return"text-green-600";if(e<36)return"text-yellow-600";return"text-red-600";case"emergency":if(e>=6)return"text-green-600";if(e>=3)return"text-yellow-600";return"text-red-600";default:return"text-gray-600"}}n.d(t,{Qt:function(){return b},WE:function(){return y},m:function(){return p},rl:function(){return E},xG:function(){return v},xZ:function(){return d},zd:function(){return w}})},7795:function(e,t,n){n.d(t,{$:function(){return m},Es:function(){return _},Rh:function(){return u},VH:function(){return o},Xc:function(){return s},eD:function(){return r.eD},em:function(){return p},nM:function(){return h},pH:function(){return i},pK:function(){return c}});var r=n(51487);let a={CURRENT_CONFIG:"home_budget_current_config",SAVED_CONFIGS:"home_budget_saved_configs"};function o(e){try{let t=i(),n=t.findIndex(t=>t.id===e.id),r={...e,last_modified:new Date().toISOString()};n>=0?t[n]=r:t.push(r),localStorage.setItem(a.SAVED_CONFIGS,JSON.stringify(t)),localStorage.setItem(a.CURRENT_CONFIG,JSON.stringify(r))}catch(e){throw console.error("Error saving configuration:",e),Error("Failed to save configuration")}}function i(){try{let e=localStorage.getItem(a.SAVED_CONFIGS);return e?JSON.parse(e):[]}catch(e){return console.error("Error loading saved configurations:",e),[]}}function c(){try{let e=localStorage.getItem(a.CURRENT_CONFIG);return e?JSON.parse(e):null}catch(e){return console.error("Error loading current configuration:",e),null}}function s(e){try{let t=i().filter(t=>t.id!==e);localStorage.setItem(a.SAVED_CONFIGS,JSON.stringify(t));let n=c();n?.id===e&&localStorage.removeItem(a.CURRENT_CONFIG)}catch(e){throw console.error("Error deleting configuration:",e),Error("Failed to delete configuration")}}function _(e){try{let t=JSON.stringify(e,null,2),n=new Blob([t],{type:"application/json"}),r=URL.createObjectURL(n),a=document.createElement("a");a.href=r,a.download=`${e.name.replace(/[^a-z0-9]/gi,"_").toLowerCase()}_budget_config.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r)}catch(e){throw console.error("Error downloading configuration:",e),Error("Failed to download configuration")}}function u(e){return new Promise((t,n)=>{try{let a=new FileReader;a.onload=e=>{try{let a=e.target?.result;if("string"==typeof a){let e=JSON.parse(a);if(!l(e)){n(Error("Invalid configuration file format"));return}let o={...e,id:(0,r.tT)(),last_modified:new Date().toISOString()};t(o)}else n(Error("Failed to read file content"))}catch(e){n(Error("Invalid JSON file format"))}},a.onerror=()=>{n(Error("Failed to read file"))},a.readAsText(e)}catch(e){n(Error("Failed to upload configuration"))}})}function l(e){try{return e&&"string"==typeof e.id&&"string"==typeof e.name&&"string"==typeof e.description&&"string"==typeof e.created_date&&"string"==typeof e.last_modified&&e.data&&Array.isArray(e.data.income_sources)&&Array.isArray(e.data.debt_accounts)&&Array.isArray(e.data.expense_categories)&&"object"==typeof e.data.housing&&"object"==typeof e.data.cash&&"object"==typeof e.data.payment_matrix&&"number"==typeof e.data.home_purchase_month}catch{return!1}}let d=null;function m(e,t=2e3){d&&clearTimeout(d),d=setTimeout(()=>{try{o(e)}catch(e){console.error("Auto-save failed:",e)}},t)}function p(){try{let e=i(),t={exported_date:new Date().toISOString(),version:"1.0",configurations:e},n=JSON.stringify(t,null,2),r=new Blob([n],{type:"application/json"}),a=URL.createObjectURL(r),o=document.createElement("a");o.href=a,o.download=`home_budget_backup_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a)}catch(e){throw console.error("Error exporting configurations:",e),Error("Failed to export configurations")}}function h(e){return new Promise((t,n)=>{try{let a=new FileReader;a.onload=e=>{try{let a=e.target?.result;if("string"==typeof a){let e=JSON.parse(a);if(e.configurations&&Array.isArray(e.configurations)){let n=e.configurations.filter(l).map(e=>({...e,id:(0,r.tT)(),last_modified:new Date().toISOString()}));t(n)}else n(Error("Invalid backup file format"))}else n(Error("Failed to read file content"))}catch(e){n(Error("Invalid backup file format"))}},a.onerror=()=>{n(Error("Failed to read file"))},a.readAsText(e)}catch(e){n(Error("Failed to import configurations"))}})}}}]);