"use client"; import { useMemo, useState } from "react"; import { Check, ChevronDown, Search } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { TOPIC_GOAL_LABELS, isPlacementGoal } from "@/lib/types/topic-goal"; import { cn } from "@/lib/utils"; export interface InspirationTopic { id: string; label: string; topicGoal: string; } interface TopicPickerProps { topics: InspirationTopic[]; selectedTopicId: string | null; onSelectTopic: (topicId: string | null) => void; } export function TopicPicker({ topics, selectedTopicId, onSelectTopic }: TopicPickerProps) { const [open, setOpen] = useState(false); const [query, setQuery] = useState(""); const selected = selectedTopicId ? topics.find((t) => t.id === selectedTopicId) ?? null : null; const filtered = useMemo(() => { const q = query.trim().toLowerCase(); if (!q) return topics; return topics.filter((t) => t.label.toLowerCase().includes(q)); }, [topics, query]); function pick(topicId: string | null) { onSelectTopic(topicId); setOpen(false); setQuery(""); } const triggerLabel = selected ? selected.label : `全部主題${topics.length > 0 ? ` · ${topics.length}` : ""}`; return ( <> 選擇主題
setQuery(e.target.value)} placeholder="搜尋主題名稱" className="pl-9" autoFocus />
{filtered.length === 0 ? (

找不到符合的主題

) : ( filtered.map((topic) => ( )) )}
); }