"use client" import { useTranslations } from "next-intl" import { Search, RotateCcw, Loader2 } from "lucide-react" import { Button } from "@/shared/components/ui/button" import { Input } from "@/shared/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/shared/components/ui/select" import type { GraphLayoutMode, GraphViewMode } from "../types" interface GraphToolbarProps { viewMode: GraphViewMode onViewModeChange: (mode: GraphViewMode) => void availableViewModes: GraphViewMode[] layoutMode: GraphLayoutMode onLayoutModeChange: (mode: GraphLayoutMode) => void searchText: string onSearchChange: (text: string) => void onResetView: () => void /** 切换模式刷新中(显示轻量指示器,保留旧数据) */ isRefreshing?: boolean } const ALL_VIEW_MODES: readonly GraphViewMode[] = [ "structure", "student-mastery", "class-mastery", ] const ALL_LAYOUT_MODES: readonly GraphLayoutMode[] = ["hierarchical", "force"] function isGraphViewMode(value: string): value is GraphViewMode { return ALL_VIEW_MODES.some((mode) => mode === value) } function isGraphLayoutMode(value: string): value is GraphLayoutMode { return ALL_LAYOUT_MODES.some((mode) => mode === value) } export function GraphToolbar({ viewMode, onViewModeChange, availableViewModes, layoutMode, onLayoutModeChange, searchText, onSearchChange, onResetView, isRefreshing, }: GraphToolbarProps) { const t = useTranslations("textbooks") const handleViewModeChange = (v: string): void => { if (isGraphViewMode(v)) { onViewModeChange(v) } } const handleLayoutModeChange = (v: string): void => { if (isGraphLayoutMode(v)) { onLayoutModeChange(v) } } return (