import React from 'react';
import { BaseDeleteModal } from '../../ui';
import { SupplierResponse, SupplierDeletionSummary } from '../../../api/types/suppliers';
import { useTranslation } from 'react-i18next';

interface DeleteSupplierModalProps {
  isOpen: boolean;
  onClose: () => void;
  supplier: SupplierResponse | null;
  onSoftDelete: (supplierId: string) => Promise<void>;
  onHardDelete: (supplierId: string) => Promise<SupplierDeletionSummary>;
  isLoading?: boolean;
}

/**
 * Modal for supplier deletion with soft/hard delete options
 * - Soft delete: Mark as inactive (reversible)
 * - Hard delete: Permanent deletion with GDPR compliance
 */
export const DeleteSupplierModal: React.FC<DeleteSupplierModalProps> = ({
  isOpen,
  onClose,
  supplier,
  onSoftDelete,
  onHardDelete,
  isLoading = false,
}) => {
  const { t } = useTranslation(['suppliers', 'common']);

  if (!supplier) return null;

  return (
    <BaseDeleteModal<SupplierResponse, SupplierDeletionSummary>
      isOpen={isOpen}
      onClose={onClose}
      entity={supplier}
      onSoftDelete={onSoftDelete}
      onHardDelete={onHardDelete}
      isLoading={isLoading}
      title={t('suppliers:delete.title', 'Eliminar Proveedor')}
      getEntityId={(sup) => sup.id}
      getEntityDisplay={(sup) => ({
        primaryText: sup.name,
        secondaryText: `${t('suppliers:delete.supplier_code', 'Código')}: ${sup.supplier_code || 'N/A'} • ${t('suppliers:delete.supplier_type', 'Tipo')}: ${sup.supplier_type}`,
      })}
      softDeleteOption={{
        title: t('suppliers:delete.soft_delete', 'Desactivar (Recomendado)'),
        description: t('suppliers:delete.soft_explanation', 'El proveedor se marca como inactivo pero conserva todo su historial. Ideal para proveedores temporalmente fuera del catálogo.'),
        benefits: t('suppliers:delete.soft_benefits', '✓ Reversible • ✓ Conserva historial • ✓ Conserva datos'),
      }}
      hardDeleteOption={{
        title: t('suppliers:delete.hard_delete', 'Eliminar Permanentemente'),
        description: t('suppliers:delete.hard_explanation', 'Elimina completamente el proveedor y todos sus datos asociados. Use solo para datos erróneos o pruebas.'),
        benefits: t('suppliers:delete.hard_risks', '⚠️ No reversible • ⚠️ Elimina historial • ⚠️ Elimina todos los datos'),
        enabled: true,
      }}
      softDeleteWarning={{
        title: t('suppliers:delete.soft_info_title', 'ℹ️ Esta acción desactivará el proveedor:'),
        items: [
          t('suppliers:delete.soft_info_1', 'El proveedor se marcará como inactivo'),
          t('suppliers:delete.soft_info_2', 'No aparecerá en listas activas'),
          t('suppliers:delete.soft_info_3', 'Se conserva todo el historial y datos'),
          t('suppliers:delete.soft_info_4', 'Se puede reactivar posteriormente'),
        ],
      }}
      hardDeleteWarning={{
        title: t('suppliers:delete.hard_warning_title', '⚠️ Esta acción eliminará permanentemente:'),
        items: [
          t('suppliers:delete.hard_warning_1', 'El proveedor y toda su información'),
          t('suppliers:delete.hard_warning_2', 'Todas las listas de precios asociadas'),
          t('suppliers:delete.hard_warning_3', 'Todo el historial de calidad y rendimiento'),
          t('suppliers:delete.hard_warning_4', 'Las alertas y scorecards relacionados'),
        ],
        footer: t('suppliers:delete.irreversible', 'Esta acción NO se puede deshacer'),
      }}
      requireConfirmText={true}
      confirmText="ELIMINAR"
      showSuccessScreen={false}
      showDeletionSummary={true}
      deletionSummaryTitle={t('suppliers:delete.summary_title', 'Eliminación Completada')}
      formatDeletionSummary={(summary) => ({
        [t('suppliers:delete.deleted_price_lists', 'Listas de precios eliminadas')]: summary.deleted_price_lists,
        [t('suppliers:delete.deleted_quality_reviews', 'Revisiones de calidad eliminadas')]: summary.deleted_quality_reviews,
        [t('suppliers:delete.deleted_performance_metrics', 'Métricas de rendimiento eliminadas')]: summary.deleted_performance_metrics,
        [t('suppliers:delete.deleted_alerts', 'Alertas eliminadas')]: summary.deleted_alerts,
        [t('suppliers:delete.deleted_scorecards', 'Scorecards eliminados')]: summary.deleted_scorecards,
      })}
    />
  );
};
