import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';

export interface ConfirmDialogData {
  title: string;
  message: string;
  confirmText?: string;
  cancelText?: string;
  confirmColor?: 'primary' | 'warn' | 'accent';
  type?: 'confirm' | 'alert' | 'warning' | 'error';
}

/**
 * Modal générique de confirmation
 * Remplace: modal-delete, modal-decconected, modal-session-expired
 */
@Component({
  selector: 'app-confirm-dialog',
  templateUrl: './confirm-dialog.component.html',
  styleUrls: ['./confirm-dialog.component.scss'],
})
export class ConfirmDialogComponent {
  constructor(
    public dialogRef: MatDialogRef<ConfirmDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: ConfirmDialogData
  ) {
    // Valeurs par défaut
    this.data.confirmText = data.confirmText || 'Confirmer';
    this.data.cancelText = data.cancelText || 'Annuler';
    this.data.confirmColor = data.confirmColor || 'primary';
    this.data.type = data.type || 'confirm';
  }

  onConfirm(): void {
    this.dialogRef.close(true);
  }

  onCancel(): void {
    this.dialogRef.close(false);
  }

  getIconClass(): string {
    const icons = {
      confirm: 'fa-question-circle text-blue-600',
      alert: 'fa-info-circle text-blue-600',
      warning: 'fa-exclamation-triangle text-yellow-600',
      error: 'fa-times-circle text-red-600',
    };
    return icons[this.data.type || 'confirm'];
  }
}
