import { Component, ViewChild } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { PlayerInfoFormComponent } from '../components/player-info-form/player-info-form.component';
import { CommonModule } from '@angular/common';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatButtonModule } from '@angular/material/button';

@Component({
  selector: 'app-create-player.dialog',
  templateUrl: './create-player.dialog.component.html',
  styleUrls: ['./create-player.dialog.component.scss'],
  standalone: true,
  imports: [ CommonModule, PlayerInfoFormComponent, MatButtonModule ]
})
export class CreatePlayerDialogComponent {
  @ViewChild('formComponent') formComponent!: PlayerInfoFormComponent;

  constructor(
    public dialogRef: MatDialogRef<CreatePlayerDialogComponent>
  ) {}


  get disableSave(): boolean {
    return !this.formComponent || !this.formComponent.form || this.formComponent?.form.invalid;
  }

  close(save?: boolean) {
    if (save) {
      this.dialogRef.close(this.formComponent.form.value);
      return;
    }

    this.dialogRef.close();
    
  }
}
