import { Component, inject } from '@angular/core'; import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { AngularMaterialModule } from '../../shared/module/angular-material.module'; import { CommonModule } from '@angular/common'; import { StepperSelectionEvent } from '@angular/cdk/stepper'; import { ApplicationComponent } from "../application/application.component"; import { HolderComponent } from '../holder/holder.component'; import { GoodsComponent } from '../goods/goods.component'; @Component({ selector: 'app-add-carnet', imports: [AngularMaterialModule, CommonModule, ReactiveFormsModule, ApplicationComponent, HolderComponent, GoodsComponent], templateUrl: './add-carnet.component.html', styleUrl: './add-carnet.component.scss' }) export class AddCarnetComponent { currentStep = 0; questionsCompleted = false; isLinear = true; applicationType: 'new' | 'additional' | 'duplicate' | 'extend' | null = null; isEditMode = false; applicationid: number = 0; private fb = inject(FormBuilder); // Form group for initial questions questionsForm: FormGroup = this.fb.group({ newCarnet: [null, Validators.required], additionalSets: [false], duplicateCarnet: [false], extendCarnet: [false] }); // Track completion of each step stepsCompleted = { applicationDetail: false, holderSelection: false, goodsSection: false, travelPlan: false, insurance: false, shipping: false, deliveryMethod: false, payment: false }; onQuestionsSubmit(): void { const answers = this.questionsForm.value; if (answers.newCarnet) { this.applicationType = 'new'; } else if (answers.additionalSets) { this.applicationType = 'additional'; } else if (answers.duplicateCarnet) { this.applicationType = 'duplicate'; } else if (answers.extendCarnet) { this.applicationType = 'extend'; } // Move to the first step after questions this.questionsCompleted = true; this.currentStep = 0; } onStepChange(event: StepperSelectionEvent): void { this.currentStep = event.selectedIndex; } onApplicationDetailCreated(applicationid: number): void { this.applicationid = applicationid; this.stepsCompleted.applicationDetail = true; this.isLinear = false; // Disable linear mode after application detail is created } onHolderSelectionSaved(completed: boolean): void { this.stepsCompleted.holderSelection = completed; } onGoodsSectionSaved(completed: boolean): void { this.stepsCompleted.goodsSection = completed; } onTravelPlanSaved(completed: boolean): void { this.stepsCompleted.travelPlan = completed; } onInsuranceSaved(completed: boolean): void { this.stepsCompleted.insurance = completed; } onShippingSaved(completed: boolean): void { this.stepsCompleted.shipping = completed; } onDeliveryMethodSaved(completed: boolean): void { this.stepsCompleted.deliveryMethod = completed; } onPaymentSaved(completed: boolean): void { this.stepsCompleted.payment = completed; } }