import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { DialogFlightCostComponent } from '../../../supervisor/components/dialog-flight-cost/dialog-flight-cost.component';

@Component({
  templateUrl: './dialog-reservation-pay.component.html',
  styleUrls: ['./dialog-reservation-pay.component.scss']
})
export class DialogReservationPayComponent implements OnInit {

  constructor(
    public dialogRef: MatDialogRef<DialogFlightCostComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any) {}
  
    payForm: FormGroup = new FormGroup({
      creditCardNumber: new FormControl('', [Validators.required, Validators.minLength(16), Validators.maxLength(16)]),
      expiration: new FormControl('', [Validators.required, Validators.minLength(5), Validators.maxLength(5)]),
      cvv: new FormControl('', [Validators.required, Validators.minLength(3), Validators.maxLength(3)]),
      owner: new FormControl('', [Validators.required, Validators.minLength(3), Validators.maxLength(50)]),
    });

  ngOnInit(): void {
    
  }

  onNoClick() {
    this.data.status = false;
    this.dialogRef.close({ status: false });
  }

  onPay() {
    const pay = {
      creditCardNumber: this.payForm.value.creditCardNumber,
      expiration: this.payForm.value.expiration,
      cvv: this.payForm.value.cvv,
      owner: this.payForm.value.owner
    }
    this.data.status = true;
    this.data.pay.status = "PAID";
    this.dialogRef.close({status: true, pay: pay});
  }
}
