import { Component, inject, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { AngularMaterialModule } from '../../shared/module/angular-material.module';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { CarnetService } from '../../core/services/carnet/carnet.service';
import { Fees } from '../../core/models/carnet/fee';
import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service';
import { NotificationService } from '../../core/services/common/notification.service';
@Component({
selector: 'app-fees-dialog',
imports: [AngularMaterialModule, CommonModule, FormsModule],
template: `
Fees and Charges
The following fees apply:
- Basic fee: {{estimatedFees.basicFee | currency}}
- Counterfoil Fee: {{estimatedFees.counterFoilFee | currency}}
- Continuation sheet fee:
{{estimatedFees.continuationSheetFee | currency}}
- Expedited fee: {{estimatedFees.expeditedFee | currency}}
- Shipping fee: {{estimatedFees.shippingFee | currency}}
- Bond Premium: {{estimatedFees.bondPremium | currency}}
- Cargo Premium: {{estimatedFees.cargoPremium | currency}}
- LDI Premium: {{estimatedFees.ldiPremium | currency}}
`,
styles: [`
li {
margin-bottom: 8px;
}
`]
})
export class FeesDialogComponent {
estimatedFees: Fees = {};
headerid: number | null = null;
private carnetService = inject(CarnetService);
private notificationService = inject(NotificationService);
private errorHandler = inject(ApiErrorHandlerService);
constructor(
public dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: { headerid: any }
) {
this.headerid = data.headerid;
}
ngOnInit(): void {
if (this.headerid && this.headerid > 0) {
this.carnetService.getEstimatedFees(this.headerid).subscribe({
next: (data: Fees) => {
if (data) {
this.estimatedFees = data;
}
},
error: (error: any) => {
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to get estimated fees');
this.notificationService.showError(errorMessage);
console.error('Error getting estimated fees:', error);
}
});
}
}
onClose(): void {
this.dialogRef.close();
}
}