import React, { useEffect, useMemo, useState } from "react"; import { motion } from "motion/react"; import { Rocket } from "lucide-react"; import DeleteButton from "src/components/ui/button/delete-button"; import SchematicButton from "src/components/ui/button/schematic-button"; export default function ChatHeader({ title = "Title of Chat", onClear, busy = false, fileSummary, errorMessage, }) { const isDebug = useMemo(() => { const p = new URLSearchParams(window.location.search); return p.get("debug") === "1"; }, []); const [ingesting, setIngesting] = useState(false); const [toast, setToast] = useState(""); const [externalToast, setExternalToast] = useState(""); useEffect(() => { if (!errorMessage) return; setExternalToast(errorMessage); const timer = window.setTimeout(() => setExternalToast(""), 5000); return () => window.clearTimeout(timer); }, [errorMessage]); async function triggerDemoIngest() { try { setIngesting(true); const res = await fetch("/api/files/import-demo", { method: "POST" }); const json = await res.json().catch(() => ({})); const imported = json.imported ?? "?"; const skipped = json.skipped ?? "?"; const summary = `Imported: ${imported}, Skipped: ${skipped}`; setToast(json.error ? `${summary} - ${json.error}` : summary); setTimeout(() => setToast(""), 4000); } catch (e) { setToast("Import failed"); setTimeout(() => setToast(""), 4000); } finally { setIngesting(false); } } return (