import { CommonModule } from '@angular/common'; import { Component, inject, ViewChild } from '@angular/core'; import { AngularMaterialModule } from '../../shared/module/angular-material.module'; import { ReactiveFormsModule } from '@angular/forms'; import { ApplicationComponent } from '../application/application.component'; import { StepperSelectionEvent } from '@angular/cdk/stepper'; import { GoodsComponent } from '../goods/goods.component'; import { HolderComponent } from '../holder/holder.component'; import { ActivatedRoute } from '@angular/router'; import { ShippingComponent } from '../shipping/shipping.component'; import { TravelPlanComponent } from '../travel-plan/travel-plan.component'; import { UserPreferences } from '../../core/models/user-preference'; import { UserPreferencesService } from '../../core/services/user-preference.service'; @Component({ selector: 'app-edit-carnet', imports: [AngularMaterialModule, CommonModule, ReactiveFormsModule, ApplicationComponent, HolderComponent, GoodsComponent, TravelPlanComponent, ShippingComponent], templateUrl: './edit-carnet.component.html', styleUrl: './edit-carnet.component.scss' }) export class EditCarnetComponent { currentStep = 0; isLinear = false; applicationType: 'new' | 'additional' | 'duplicate' | 'extend' | null = 'new'; isEditMode = true; // Set to true for edit mode headerid: number = 0; userPreferences: UserPreferences; applicationName: string = ''; allSectionsCompleted: boolean = false; @ViewChild(ShippingComponent, { static: false }) private shippingComponent!: ShippingComponent; // Track completion of each step stepsCompleted = { applicationDetail: true, holderSelection: false, goodsSection: false, travelPlan: false, shipping: false }; private route = inject(ActivatedRoute); constructor(userPrefenceService: UserPreferencesService) { this.userPreferences = userPrefenceService.getPreferences(); } ngOnInit(): void { const idParam = this.route.snapshot.paramMap.get('headerid'); this.headerid = idParam ? parseInt(idParam, 10) : 0; this.applicationName = this.route.snapshot.queryParamMap.get('applicationname') || ''; let returnTo = this.route.snapshot.queryParamMap.get('return'); if (returnTo === 'holder') { this.currentStep = 1; } else if (returnTo === 'shipping') { this.currentStep = 4; } } onStepChange(event: StepperSelectionEvent): void { this.currentStep = event.selectedIndex; } onHolderSelectionSaved(completed: boolean): void { this.stepsCompleted.holderSelection = completed; this.isAllSectionsCompleted(); } onGoodsSectionSaved(completed: boolean): void { this.stepsCompleted.goodsSection = completed; this.isAllSectionsCompleted(); } onHolderSelectionUpdated(updated: boolean): void { if (updated) { this.shippingComponent?.refreshShippingData(); } this.isAllSectionsCompleted(); } onTravelPlanSaved(completed: boolean): void { this.stepsCompleted.travelPlan = completed; this.isAllSectionsCompleted(); } onShippingSaved(completed: boolean): void { this.stepsCompleted.shipping = completed; this.isAllSectionsCompleted(); } isAllSectionsCompleted() { this.allSectionsCompleted = this.stepsCompleted.applicationDetail && this.stepsCompleted.holderSelection && this.stepsCompleted.goodsSection && this.stepsCompleted.shipping && this.stepsCompleted.travelPlan; } }