import { BookX } from "lucide-react"

import { EmptyState } from "@/shared/components/ui/empty-state"
import { Button } from "@/shared/components/ui/button"
import { ErrorBookItemCard } from "./error-book-item-card"
import { ErrorBookDetailDialog } from "./error-book-detail-dialog"
import type { ErrorBookItem } from "../types"

interface ErrorBookListProps {
  items: ErrorBookItem[]
  /** 当前学生 ID（用于 AI 薄弱点分析） */
  studentId?: string
  /** 全部错题列表（用于 AI 薄弱点分析，不传则禁用 AI 分析） */
  errorItems?: ErrorBookItem[]
}

export function ErrorBookList({ items, studentId, errorItems }: ErrorBookListProps) {
  if (items.length === 0) {
    return (
      <EmptyState
        icon={BookX}
        title="错题本为空"
        description="完成考试或作业后，错题会自动收录到这里。你也可以手动添加错题。"
        className="h-[360px] bg-card"
      />
    )
  }

  return (
    <div className="grid gap-3 md:grid-cols-2">
      {items.map((item) => (
        <ErrorBookItemCard key={item.id} item={item}>
          <ErrorBookDetailDialog
            item={item}
            studentId={studentId}
            errorItems={errorItems}
            trigger={
              <Button variant="outline" size="sm">
                查看详情
              </Button>
            }
          />
        </ErrorBookItemCard>
      ))}
    </div>
  )
}
