'use client';
import { Employee } from './EmployeesContent';
import { useState } from 'react';

interface Props {
  employee: Employee;
  onConfirm: () => Promise<void>;
  onClose: () => void;
}

export default function DeleteConfirmModal({ employee, onConfirm, onClose }: Props) {
  const [isDeleting, setIsDeleting] = useState(false);

  const handleConfirm = async () => {
    setIsDeleting(true);
    try {
      await onConfirm();
      // Close modal - toast will show success message in parent component
      onClose();
    } catch (error) {
      console.error('Delete failed:', error);
      setIsDeleting(false);
    }
  };

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-2xl p-6 w-[420px] shadow-2xl">
        <div className="flex flex-col items-center text-center">
          {/* Warning Icon */}
          <div className="w-16 h-16 rounded-full bg-red-100 flex items-center justify-center mb-4">
            <i className="ri-delete-bin-line text-red-500 text-3xl"></i>
          </div>
          
          {/* Title */}
          <h2 className="text-lg font-bold text-gray-800 mb-2">Delete Employee</h2>
          
          {/* Employee Name */}
          <p className="text-sm text-gray-500 mb-1">
            Are you sure you want to delete <span className="font-semibold text-gray-800">{employee.name}</span>?
          </p>
          
          {/* Employee Details */}
          <p className="text-xs text-gray-400 mb-6">
            Emp ID: {employee.employeeNumber} &bull; {employee.dept}
          </p>
          
          {/* Warning Message */}
          <div className="bg-red-50 border border-red-100 rounded-lg px-4 py-3 mb-6 w-full text-left">
            <p className="text-xs text-red-600 font-medium mb-2">⚠️ This action cannot be undone and will permanently delete:</p>
            <ul className="text-xs text-red-500 space-y-1">
              <li className="flex items-center gap-2">
                <i className="ri-user-line text-xs"></i> User account
              </li>
              <li className="flex items-center gap-2">
                <i className="ri-calendar-line text-xs"></i> Leave requests
              </li>
              <li className="flex items-center gap-2">
                <i className="ri-file-list-line text-xs"></i> Training records
              </li>
              <li className="flex items-center gap-2">
                <i className="ri-bar-chart-line text-xs"></i> Appraisals
              </li>
              <li className="flex items-center gap-2">
                <i className="ri-task-line text-xs"></i> Work plans & KPIs
              </li>
            </ul>
          </div>
          
          {/* Action Buttons */}
          <div className="flex gap-3 w-full">
            <button 
              onClick={onClose} 
              disabled={isDeleting}
              className="flex-1 border border-gray-200 text-gray-600 py-2.5 rounded-lg text-sm font-medium hover:bg-gray-50 cursor-pointer whitespace-nowrap transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
            >
              Cancel
            </button>
            <button 
              onClick={handleConfirm} 
              disabled={isDeleting}
              className="flex-1 bg-red-600 text-white py-2.5 rounded-lg text-sm font-medium hover:bg-red-700 cursor-pointer whitespace-nowrap transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
            >
              {isDeleting ? (
                <>
                  <div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
                  Deleting...
                </>
              ) : (
                'Yes, Delete'
              )}
            </button>
          </div>
        </div>
      </div>
    </div>
  );
}