import { Component, Inject } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { NanoDialogBaseComponent } from '../nano-base-dialog';

export interface DialogData {
  name: string;
}

@Component({
  selector: 'app-create-room-dialog',
  templateUrl: './create-room-dialog.component.html',
  styleUrls: ['./create-room-dialog.component.scss'],
})
export class CreateRoomDialogComponent extends NanoDialogBaseComponent<CreateRoomDialogComponent> {
  roomNameControl = new UntypedFormControl('', [Validators.required, Validators.maxLength(35)]);

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

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