import {ChangeDetectionStrategy, Component, EventEmitter, Inject, inject, Output, signal} from '@angular/core';
import {MatButtonModule} from "@angular/material/button";
import {
  MAT_DIALOG_DATA,
  MatDialogActions,
  MatDialogClose,
  MatDialogContent,
  MatDialogRef,
  MatDialogTitle
} from "@angular/material/dialog";


import {MatFormField, MatLabel, MatSuffix} from "@angular/material/form-field";
import {MatInput} from "@angular/material/input";
import {FormsModule} from "@angular/forms";
import {MatIcon} from "@angular/material/icon";
import {DialogLoginData} from '../../main-module/main.component/main.component';
import {MatSnackBar} from '@angular/material/snack-bar';




@Component({
    selector: 'app-dialog',
    imports: [MatButtonModule, MatLabel, MatDialogActions, MatDialogClose, MatDialogTitle, MatDialogContent, MatFormField, MatInput, FormsModule, MatIcon,  MatSuffix],

    templateUrl: './dialog.component.html',
    styleUrl: './dialog.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class DialogComponent {
  readonly dialogRef = inject(MatDialogRef<DialogComponent>);
  hide = signal(true);

  @Output() loginClicked = new EventEmitter<any>();
  @Output() signupClicked = new EventEmitter<any>();

  private _snackBar = inject(MatSnackBar);
  durationInSeconds = 5;


  constructor(
    @Inject(MAT_DIALOG_DATA) public data:DialogLoginData) {

  }

  openLoginFailedSnackBar(errorMessage : string = "Login failed.") {
    this._snackBar.open(errorMessage , "", {
      duration: this.durationInSeconds * 1000,
    });
  }

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


  clickEvent(event: MouseEvent) {
    this.hide.set(!this.hide());
    event.stopPropagation();
  }

  login() {
    this.loginClicked.emit(this.data);

  }

  signup() {
    this.signupClicked.emit();
  }
}



