import React from 'react';
import { AlertTriangle, X } from 'lucide-react';
import type { SupplierRecord } from '../types';
import { canDeleteSupplier } from '../utils/permissions';

interface DeleteConfirmModalProps {
  open: boolean;
  record: SupplierRecord | null;
  onClose: () => void;
  onConfirm: () => void;
}

export function DeleteConfirmModal({
  open,
  record,
  onClose,
  onConfirm,
}: DeleteConfirmModalProps) {
  if (!open || !record) return null;

  const deletable = canDeleteSupplier(record);

  return (
    <div className="vm-modal-backdrop" role="presentation" onClick={onClose}>
      <div
        className="vm-modal vm-modal-sm"
        role="dialog"
        aria-modal="true"
        aria-labelledby="sm-delete-title"
        onClick={(event) => event.stopPropagation()}
      >
        <header className="vm-modal-header">
          <h2 id="sm-delete-title">{deletable ? '确认删除供应商' : '确认停用供应商'}</h2>
          <button type="button" className="vm-modal-close" onClick={onClose} aria-label="关闭">
            <X size={18} aria-hidden />
          </button>
        </header>
        <div className="sm-modal-body">
          <div className="sm-modal-alert">
            <AlertTriangle size={18} aria-hidden />
            <div>
              {deletable ? (
                <p>
                  确定删除供应商「{record.supplierName}」吗？删除后不可恢复（原型演示）。
                </p>
              ) : (
                <>
                  <p>
                    供应商「{record.supplierName}」已关联
                    {record.hasLinkedContract && '合同'}
                    {record.hasLinkedContract && record.hasLinkedPayment && '、'}
                    {record.hasLinkedPayment && '付款记录'}
                    ，不可删除，仅可停用。
                  </p>
                  <p className="sm-modal-sub">停用后该供应商将不再参与新业务，历史数据保留。</p>
                </>
              )}
            </div>
          </div>
        </div>
        <footer className="vm-modal-footer">
          <button type="button" className="vm-btn vm-btn-ghost" onClick={onClose}>取消</button>
          <button type="button" className="vm-btn vm-btn-primary" onClick={onConfirm}>
            {deletable ? '确认删除' : '确认停用'}
          </button>
        </footer>
      </div>
    </div>
  );
}
