"use client"

import { useTranslations } from "next-intl"
import { Loader2, Trash2 } from "lucide-react"
import { type ReactElement } from "react"

import { Button } from "@/shared/components/ui/button"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/shared/components/ui/alert-dialog"

interface AiProviderDeleteDialogProps {
  /** 是否禁用删除按钮（无选中项或正在执行其他操作时） */
  disabled: boolean
  /** 是否正在执行删除操作 */
  isPending: boolean
  /** 确认删除回调 */
  onConfirm: () => void
}

/**
 * AI 服务商删除确认对话框
 *
 * 仅负责删除确认交互，具体删除逻辑由父组件通过 onConfirm 回调注入。
 */
export function AiProviderDeleteDialog({
  disabled,
  isPending,
  onConfirm,
}: AiProviderDeleteDialogProps): ReactElement {
  const t = useTranslations("settings.ai.providers")

  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button
          type="button"
          variant="destructive"
          disabled={disabled}
        >
          <Trash2 className="mr-2 h-4 w-4" />
          {t("delete")}
        </Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>{t("deleteConfirmTitle")}</AlertDialogTitle>
          <AlertDialogDescription>{t("deleteConfirmDescription")}</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>{t("deleteCancel")}</AlertDialogCancel>
          <AlertDialogAction onClick={onConfirm}>
            {isPending ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
            {t("deleteConfirm")}
          </AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
