"use client";

import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/Button";
import { Modal } from "@/components/ui/Modal";

/**
 * Confirming the removal of one registration.
 *
 * The question names the volunteer, because the organizer reaches this from a
 * row in a long table and the modal is the last chance to notice the wrong one.
 */
export default function DeleteRegistrationModal({
  open,
  onClose,
  onConfirm,
  isDeleting,
  userName,
  hasHistory = false,
}: {
  open: boolean;
  onClose: () => void;
  onConfirm: () => void;
  isDeleting: boolean;
  userName: string;
  /** Attended or certified: removing them archives that record (BE-138). */
  hasHistory?: boolean;
}) {
  const { t } = useTranslation();

  return (
    <Modal
      open={open}
      onClose={() => !isDeleting && onClose()}
      title={t("COMMON.DELETE_REGISTRATION")}
      size="sm"
      footer={
        <div className="flex xss:flex-col justify-center w-full gap-5">
          <Button
            variant="primary"
            size="medium"
            onClick={onConfirm}
            disabled={isDeleting}
            className="xss:!w-full"
          >
            {t("COMMON.DELETE")}
          </Button>
          <Button
            variant="secondary"
            size="medium"
            onClick={onClose}
            className="xss:!w-full"
          >
            {t("COMMON.CANCEL")}
          </Button>
        </div>
      }
    >
      <div className="pb-10 text-center text-lg">
        {t("COMMON.DELETE_VOLUNTEER_REGISTRATION", { name: userName })}
        {hasHistory && (
          <p className="mt-3 text-sm text-[#B45309]">
            {t("COMMON.REMOVE_WITH_HISTORY_WARNING")}
          </p>
        )}
      </div>
    </Modal>
  );
}
