import React from 'react';
import { BaseDeleteModal } from '../../ui';
import { QualityCheckTemplate } from '../../../api/types/qualityTemplates';
import { useTranslation } from 'react-i18next';

interface DeleteQualityTemplateModalProps {
  isOpen: boolean;
  onClose: () => void;
  template: QualityCheckTemplate | null;
  onSoftDelete: (templateId: string) => Promise<void>;
  onHardDelete: (templateId: string) => Promise<void>;
  isLoading?: boolean;
}

/**
 * Modal for quality template deletion with soft/hard delete options
 * - Soft delete: Mark as inactive (reversible)
 * - Hard delete: Permanent deletion with dependency checking
 */
export const DeleteQualityTemplateModal: React.FC<DeleteQualityTemplateModalProps> = ({
  isOpen,
  onClose,
  template,
  onSoftDelete,
  onHardDelete,
  isLoading = false,
}) => {
  const { t } = useTranslation(['production', 'common']);

  if (!template) return null;

  return (
    <BaseDeleteModal<QualityCheckTemplate>
      isOpen={isOpen}
      onClose={onClose}
      entity={template}
      onSoftDelete={onSoftDelete}
      onHardDelete={onHardDelete}
      isLoading={isLoading}
      title={t('production:quality.delete.title', 'Eliminar Plantilla de Calidad')}
      getEntityId={(temp) => temp.id}
      getEntityDisplay={(temp) => ({
        primaryText: temp.name,
        secondaryText: `${t('production:quality.delete.template_code', 'Código')}: ${temp.template_code || 'N/A'} • ${t('production:quality.delete.check_type', 'Tipo')}: ${temp.check_type}`,
      })}
      softDeleteOption={{
        title: t('production:quality.delete.soft_delete', 'Desactivar (Recomendado)'),
        description: t('production:quality.delete.soft_explanation', 'La plantilla se marca como inactiva pero conserva todo su historial. Ideal para plantillas temporalmente fuera de uso.'),
        benefits: t('production:quality.delete.soft_benefits', '✓ Reversible • ✓ Conserva historial • ✓ Conserva datos'),
      }}
      hardDeleteOption={{
        title: t('production:quality.delete.hard_delete', 'Eliminar Permanentemente'),
        description: t('production:quality.delete.hard_explanation', 'Elimina completamente la plantilla y todos sus datos asociados. Use solo para datos erróneos o pruebas.'),
        benefits: t('production:quality.delete.hard_risks', '⚠️ No reversible • ⚠️ Elimina historial • ⚠️ Elimina todos los datos'),
        enabled: true,
      }}
      softDeleteWarning={{
        title: t('production:quality.delete.soft_info_title', 'ℹ️ Esta acción desactivará la plantilla:'),
        items: [
          t('production:quality.delete.soft_info_1', 'La plantilla se marcará como inactiva'),
          t('production:quality.delete.soft_info_2', 'No aparecerá en listas activas'),
          t('production:quality.delete.soft_info_3', 'Se conserva todo el historial y datos'),
          t('production:quality.delete.soft_info_4', 'Se puede reactivar posteriormente'),
        ],
      }}
      hardDeleteWarning={{
        title: t('production:quality.delete.hard_warning_title', '⚠️ Esta acción eliminará permanentemente:'),
        items: [
          t('production:quality.delete.hard_warning_1', 'La plantilla y toda su información'),
          t('production:quality.delete.hard_warning_2', 'Todas las configuraciones de calidad asociadas'),
          t('production:quality.delete.hard_warning_3', 'Todo el historial de controles de calidad'),
          t('production:quality.delete.hard_warning_4', 'Las alertas y métricas relacionadas'),
        ],
        footer: t('production:quality.delete.irreversible', 'Esta acción NO se puede deshacer'),
      }}
      requireConfirmText={true}
      confirmText="ELIMINAR"
      showSuccessScreen={true}
      successTitle={t('production:quality.delete.success_soft_title', 'Plantilla Desactivada')}
      getSuccessMessage={(temp, mode) =>
        mode === 'hard'
          ? t('production:quality.delete.template_deleted', { name: temp.name })
          : t('production:quality.delete.template_deactivated', { name: temp.name })
      }
      autoCloseDelay={1500}
    />
  );
};

export default DeleteQualityTemplateModal;
