"use client";

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

interface ConfirmActionModalProps {
  open: boolean;
  onClose: () => void;
  title: string;
  /** The already-translated question. */
  message: string;
  onConfirm: () => void;
  /** Disables both buttons while the request is in flight. */
  isPending?: boolean;
}

/**
 * Title, one question, Confirm / Cancel.
 *
 * The development detail page had five of these written out in full, identical
 * apart from the title, the question and the handler — including the same
 * `xss:!w-full` on both buttons, which is what makes them stack rather than
 * squeeze on a phone. One component keeps that identical, and keeps a sixth
 * confirmation from being a sixth copy.
 */
export default function ConfirmActionModal({
  open,
  onClose,
  title,
  message,
  onConfirm,
  isPending = false,
}: ConfirmActionModalProps) {
  const { t } = useTranslation();

  return (
    <Modal open={open} onClose={onClose} title={title} size="sm">
      <div className="text-center pb-6 text-lg">{message}</div>
      <div className="flex justify-center w-full gap-5">
        <Button
          variant="primary"
          type="button"
          size="medium"
          onClick={onConfirm}
          disabled={isPending}
          className="xss:!w-full"
        >
          {t("COMMON.CONFIRM")}
        </Button>
        <Button
          variant="secondary"
          size="medium"
          type="button"
          onClick={onClose}
          disabled={isPending}
          className="xss:!w-full"
        >
          {t("COMMON.CANCEL")}
        </Button>
      </div>
    </Modal>
  );
}
