"use client";
import { useSidebar } from "ui/sidebar";
import { Tooltip, TooltipContent, TooltipTrigger } from "ui/tooltip";
import {
AudioWaveformIcon,
ChevronDown,
MessageCircleDashed,
PanelLeft,
} from "lucide-react";
import { Button } from "ui/button";
import { Separator } from "ui/separator";
import { useEffect, useMemo } from "react";
import { ThreadDropdown } from "../thread-dropdown";
import { appStore } from "@/app/store";
import { usePathname, useSearchParams } from "next/navigation";
import { useShallow } from "zustand/shallow";
import { getShortcutKeyList, Shortcuts } from "lib/keyboard-shortcuts";
import { useTranslations } from "next-intl";
import { TextShimmer } from "ui/text-shimmer";
import { buildReturnUrl } from "lib/admin/navigation-utils";
import { BackButton } from "@/components/layouts/back-button";
export function AppHeader() {
const t = useTranslations();
const [appStoreMutate] = appStore(useShallow((state) => [state.mutate]));
const { toggleSidebar, open } = useSidebar();
const currentPaths = usePathname();
const searchParams = useSearchParams();
const showActionButtons = useMemo(() => {
if (currentPaths.startsWith("/admin")) {
return false;
}
return true;
}, [currentPaths]);
const componentByPage = useMemo(() => {
if (currentPaths.startsWith("/chat/")) {
return ;
}
if (
currentPaths.startsWith("/admin/users/") &&
currentPaths.split("/").length > 3
) {
const searchPageParams = searchParams.get("searchPageParams");
const returnUrl = buildReturnUrl("/admin/users", searchPageParams || "");
return (
);
}
}, [currentPaths, searchParams]);
return (
{t("KeyboardShortcuts.toggleSidebar")}
{getShortcutKeyList(Shortcuts.toggleSidebar).map((key) => (
{key}
))}
{componentByPage}
{showActionButtons && (
{t("KeyboardShortcuts.toggleVoiceChat")}
{getShortcutKeyList(Shortcuts.toggleVoiceChat).map((key) => (
{key}
))}
{t("KeyboardShortcuts.toggleTemporaryChat")}
{getShortcutKeyList(Shortcuts.toggleTemporaryChat).map(
(key) => (
{key}
),
)}
)}
);
}
function ThreadDropdownComponent() {
const [threadList, currentThreadId, generatingTitleThreadIds] = appStore(
useShallow((state) => [
state.threadList,
state.currentThreadId,
state.generatingTitleThreadIds,
]),
);
const currentThread = useMemo(() => {
return threadList.find((thread) => thread.id === currentThreadId);
}, [threadList, currentThreadId]);
useEffect(() => {
if (currentThread?.id) {
document.title = currentThread.title || "New Chat";
}
}, [currentThread?.id]);
if (!currentThread) return null;
return (
{currentThread.title || "New Chat"}
);
}