"use client"; import { useQuery } from "@tanstack/react-query"; import { useParams, usePathname } from "next/navigation"; import { NotificationButton } from "@/components/notifications/NotificationButton"; import { ChatShareButton } from "@/components/new-chat/chat-share-button"; import { getThreadFull } from "@/lib/chat/thread-persistence"; import type { ChatVisibility } from "@/lib/chat/thread-persistence"; interface HeaderProps { breadcrumb?: React.ReactNode; mobileMenuTrigger?: React.ReactNode; } export function Header({ breadcrumb, mobileMenuTrigger, }: HeaderProps) { const params = useParams(); const pathname = usePathname(); // Check if we're on a chat page const isChatPage = pathname?.includes("/new-chat") ?? false; // Get chat_id from URL params const chatId = params?.chat_id ? Number(Array.isArray(params.chat_id) ? params.chat_id[0] : params.chat_id) : null; // Fetch current thread if on chat page and chat_id exists const { data: currentThread } = useQuery({ queryKey: ["thread", chatId], queryFn: () => getThreadFull(chatId!), enabled: isChatPage && chatId !== null && chatId > 0, }); const handleVisibilityChange = (visibility: ChatVisibility) => { // Visibility change is handled by ChatShareButton internally // This callback can be used for additional side effects if needed }; return (
{/* Left side - Mobile menu trigger + Breadcrumb */}
{mobileMenuTrigger}
{breadcrumb}
{/* Right side - Actions */}
{/* Notifications */} {/* Share button - only show on chat pages when thread exists */} {isChatPage && currentThread && ( )}
); }