"use client"; import { ChevronDown, ChevronUp, Search, X } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { searchTopics, type SearchSheet, type TopicSearchResult } from "@/lib/flow-board/topic-search"; export function XmindSearchPanel({ sheets, activeSheetId, onJump, onReplace, onClose }: { sheets: SearchSheet[]; activeSheetId: string; onJump: (result: TopicSearchResult) => void; onReplace: (results: TopicSearchResult[], query: string, replacement: string, caseSensitive: boolean) => void; onClose: () => void; }) { const [query, setQuery] = useState(""); const [replacement, setReplacement] = useState(""); const [caseSensitive, setCaseSensitive] = useState(false); const [scope, setScope] = useState("current"); const [activeIndex, setActiveIndex] = useState(0); const input = useRef(null); const results = searchTopics(scope === "all" ? sheets : sheets.filter(sheet => sheet.id === activeSheetId),query,caseSensitive); useEffect(() => { input.current?.focus(); }, []); useEffect(() => { setActiveIndex(0); }, [query,caseSensitive,scope]); const navigate = (step: number) => { if (!results.length) return; const next = (Math.min(activeIndex,results.length - 1) + step + results.length) % results.length; setActiveIndex(next); onJump(results[next]); }; return ; }