import { Component, Inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';

// Interfaccia per i dati passati al dialog
export interface ConfirmDialogData {
  title: string;
  message: string;
  confirmButtonText?: string;
  cancelButtonText?: string;
}

@Component({
  selector: 'app-confirm-dialog',
  standalone: true,
  imports: [
    CommonModule,
    MatDialogModule,
    MatButtonModule
  ],
  templateUrl: './confirm-dialog.component.html',
  styleUrl: './confirm-dialog.component.scss'
})
export class ConfirmDialogComponent {

  // Valori di default se non specificati
  title: string;
  message: string;
  confirmButtonText: string;
  cancelButtonText: string;

  constructor(
    public dialogRef: MatDialogRef<ConfirmDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: ConfirmDialogData
  ) {
    // Assegna i valori dai dati passati o usa i default
    this.title = data.title;
    this.message = data.message;
    this.confirmButtonText = data.confirmButtonText || 'Conferma';
    this.cancelButtonText = data.cancelButtonText || 'Annulla';
  }

  onConfirm(): void {
    // Chiude il dialog restituendo true per indicare la conferma
    this.dialogRef.close(true);
  }

  onDismiss(): void {
    // Chiude il dialog restituendo false per indicare l'annullamento
    this.dialogRef.close(false);
  }
}
