import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
import { NanoDialogBase } from '../nano-base-dialog';

export interface DialogData {
  name: string;
}

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

  groupNameControl = new FormControl('', [Validators.required, Validators.maxLength(35)]);

  constructor(
    public dialogRef: MatDialogRef<NewGroupDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: DialogData) {
      super(dialogRef);
      this.groupNameControl.setValue(data.name);
    }

  onNoClick(): void {
    this.dialogRef.close();
  }

  ngOnInit(): void {
  }

  onSubmit(){
    this.dialogRef.close(this.groupNameControl.value);
  }

}
