@@ -46,6 +46,7 @@ export class YnabComponent implements OnInit {
4646 public expectedAnnualGrowthRate = 7.0 ;
4747 public expectedExternalAnnualContributions = 0 ;
4848 public additionalLumpSumNeeded = 0 ;
49+ public targetRetirementAge : number | null = 65 ;
4950
5051 public budgets : ynab . BudgetSummary [ ] ;
5152 public budget : ynab . BudgetDetail ;
@@ -153,6 +154,17 @@ export class YnabComponent implements OnInit {
153154 this . birthdate = null ;
154155 }
155156
157+ const targetRetirementAgeRaw = window . localStorage . getItem ( 'br4-target-retirement-age' ) ;
158+ if ( targetRetirementAgeRaw === '' ) {
159+ // User explicitly cleared the value
160+ this . targetRetirementAge = null ;
161+ } else if ( targetRetirementAgeRaw !== null ) {
162+ const parsed = parseFloat ( targetRetirementAgeRaw ) ;
163+ if ( ! isNaN ( parsed ) ) {
164+ this . targetRetirementAge = parsed ;
165+ }
166+ }
167+
156168 // Load scheduled changes state from localStorage
157169 try {
158170 const storedState = JSON . parse (
@@ -219,6 +231,10 @@ export class YnabComponent implements OnInit {
219231 this . expectedExternalAnnualContributions ,
220232 ] ,
221233 additionalLumpSumNeeded : [ this . additionalLumpSumNeeded ] ,
234+ targetRetirementAge : [
235+ this . targetRetirementAge ,
236+ [ Validators . required , Validators . min ( 18 ) , Validators . max ( 120 ) ] ,
237+ ] ,
222238 } ) ;
223239 }
224240
@@ -338,6 +354,9 @@ export class YnabComponent implements OnInit {
338354 this . expectedExternalAnnualContributions ,
339355 ) ;
340356 result . additionalLumpSumNeeded = Math . max ( 0 , this . additionalLumpSumNeeded ) ;
357+ result . targetRetirementAge = this . targetRetirementAge !== null
358+ ? Math . max ( 18 , Math . min ( 120 , this . targetRetirementAge ) )
359+ : null ;
341360
342361 result . roundAll ( ) ;
343362 this . calculateInputChange . emit ( result ) ;
@@ -496,6 +515,21 @@ export class YnabComponent implements OnInit {
496515 parsedAdditionalLumpSum . toString ( ) ,
497516 ) ;
498517 }
518+
519+ const parsedTargetRetirementAge = Number . parseFloat (
520+ this . budgetForm . value . targetRetirementAge ,
521+ ) ;
522+ if ( ! Number . isNaN ( parsedTargetRetirementAge ) ) {
523+ this . targetRetirementAge = parsedTargetRetirementAge ;
524+ window . localStorage . setItem (
525+ 'br4-target-retirement-age' ,
526+ parsedTargetRetirementAge . toString ( ) ,
527+ ) ;
528+ } else {
529+ this . targetRetirementAge = null ;
530+ // Store empty string to remember user explicitly cleared the value
531+ window . localStorage . setItem ( 'br4-target-retirement-age' , '' ) ;
532+ }
499533 }
500534
501535 handleFormChanges ( ) {
@@ -1149,6 +1183,7 @@ export class YnabComponent implements OnInit {
11491183 expectedExternalAnnualContributions :
11501184 this . expectedExternalAnnualContributions ,
11511185 additionalLumpSumNeeded : this . additionalLumpSumNeeded ,
1186+ targetRetirementAge : this . targetRetirementAge ,
11521187 } ) ;
11531188
11541189 const categoryGroupFormGroups = categoriesDisplay . map ( ( cg ) =>
0 commit comments