"use client"

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from "@/shared/components/ui/alert-dialog"
import { useTranslations } from "next-intl"

type HomeworkTakeConfirmDialogProps = {
  open: boolean
  onOpenChange: (open: boolean) => void
  unansweredCount: number
  isBusy: boolean
  onConfirm: () => void
}

/**
 * 学生作答页 —— 提交二次确认对话框。
 *
 * 根据未作答数量显示不同的确认文案：
 * - 有未作答：警告"您有 N 道题未作答"
 * - 全部作答：常规确认"所有题目已作答"
 */
export function HomeworkTakeConfirmDialog({
  open,
  onOpenChange,
  unansweredCount,
  isBusy,
  onConfirm,
}: HomeworkTakeConfirmDialogProps) {
  const t = useTranslations("examHomework")

  return (
    <AlertDialog open={open} onOpenChange={onOpenChange}>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>{t("homework.take.confirmSubmit")}</AlertDialogTitle>
          <AlertDialogDescription>
            {unansweredCount > 0
              ? t("homework.take.unansweredWarning", { count: unansweredCount })
              : t("homework.take.confirmSubmitDescription")}
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel disabled={isBusy}>{t("homework.take.cancel")}</AlertDialogCancel>
          <AlertDialogAction
            disabled={isBusy}
            onClick={(e) => {
              e.preventDefault()
              onOpenChange(false)
              onConfirm()
            }}
          >
            {isBusy ? t("homework.take.submitting") : t("homework.take.confirmSubmitAction")}
          </AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
