"use client"; import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { useLessonPlanEditor } from "../../hooks/use-lesson-plan-editor"; import { QuestionBankPicker } from "../question-bank-picker"; import { InlineQuestionEditor } from "../inline-question-editor"; import { PublishHomeworkDialog } from "../publish-homework-dialog"; import { LessonPlanErrorBoundary } from "../lesson-plan-error-boundary"; import { Button } from "@/shared/components/ui/button"; import { Plus, Trash2 } from "lucide-react"; import type { ExerciseBlockData, ExerciseItem, } from "../../types"; import { isExercisePurpose } from "../../lib/type-guards"; interface Props { blockId: string; data: ExerciseBlockData; classes: { id: string; name: string }[]; textbookId?: string; chapterId?: string; } export function ExerciseBlock({ blockId, data, classes, textbookId, chapterId }: Props) { const t = useTranslations("lessonPreparation"); const router = useRouter(); const { updateNode, planId } = useLessonPlanEditor(); const [showBank, setShowBank] = useState(false); const [showInline, setShowInline] = useState(false); const [showPublish, setShowPublish] = useState(false); function update(patch: Partial) { updateNode(blockId, { data: { ...data, ...patch } }); } function addItems(items: ExerciseItem[]) { const next = [...data.items, ...items]; update({ items: next.map((it, i) => ({ ...it, order: i })), }); } function removeItem(idx: number) { update({ items: data.items .filter((_, i) => i !== idx) .map((it, i) => ({ ...it, order: i })), }); } return (
{data.items.length === 0 ? (

{t("questionBank.empty")}

) : ( )}
{data.publishedAssignmentId ? (
{t("status.publishedAsHomework")} {/* V4 P1-5 修复:原生 替换为 next/link 的 */} {t("action.viewHomework")}
) : ( data.purpose === "after_class_homework" && data.items.length > 0 && ( ) )}
{showBank && ( i.questionId)} onPick={addItems} onClose={() => setShowBank(false)} /> )} {showInline && ( { addItems([item]); setShowInline(false); }} onClose={() => setShowInline(false)} /> )} {showPublish && ( setShowPublish(false)} onPublished={() => router.refresh()} /> )}
); }