import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog';
import { NanoDialogBase } from 'src/app/shared/dialogs/nano-base-dialog';

@Component({
  selector: 'app-redeem-token-dialog',
  templateUrl: './redeem-token-dialog.component.html',
  styleUrls: ['./redeem-token-dialog.component.scss']
})
export class RedeemTokenDialogComponent extends NanoDialogBase<RedeemTokenDialogComponent> implements OnInit {

  redeemForm = new FormGroup({
    redeemCode: new FormControl('', [Validators.required])
  });

  constructor(public dialogRef: MatDialogRef<RedeemTokenDialogComponent>) { 
    super(dialogRef);
  }

  ngOnInit(): void {
  }

  public redeem(): void{
    if(!this.redeemForm.valid) return;

    this.dialogRef.close(this.redeemForm.get('redeemCode').value);
  }
}
