"use client"; import { usePathname, useRouter } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import PropTypes from "prop-types"; import ThemeToggle from "./ThemeToggle"; import TokenHealthBadge from "./TokenHealthBadge"; import DegradationBadge from "./DegradationBadge"; import LanguageSelector from "./LanguageSelector"; import ProviderIcon from "./ProviderIcon"; import { useTranslations } from "next-intl"; import { OAUTH_PROVIDERS, APIKEY_PROVIDERS, FREE_PROVIDERS, CLAUDE_CODE_COMPATIBLE_PREFIX, OPENAI_COMPATIBLE_PREFIX, ANTHROPIC_COMPATIBLE_PREFIX, } from "@/shared/constants/providers"; import { useIsElectron } from "@/shared/hooks/useElectron"; const isE2EMode = process.env.NEXT_PUBLIC_OMNIROUTE_E2E_MODE === "1"; function usePageInfo(pathname: string | null): { title: string; description: string; breadcrumbs: { label: string; href?: string; image?: string; providerId?: string }[]; } { const t = useTranslations("header"); if (!pathname) return { title: "", description: "", breadcrumbs: [] }; // Provider detail page: /dashboard/providers/[id] const providerMatch = pathname.match(/\/providers\/([^/]+)$/); if (providerMatch) { const providerId = providerMatch[1]; const providerInfo = OAUTH_PROVIDERS[providerId] || FREE_PROVIDERS[providerId] || APIKEY_PROVIDERS[providerId]; if (providerInfo) { return { title: providerInfo.name, description: "", breadcrumbs: [ { label: t("providers"), href: "/dashboard/providers" }, { label: providerInfo.name, providerId: providerInfo.id }, ], }; } if (providerId.startsWith(CLAUDE_CODE_COMPATIBLE_PREFIX)) { return { title: "CC Compatible", description: "", breadcrumbs: [ { label: t("providers"), href: "/dashboard/providers" }, { label: "CC Compatible", providerId: "claude" }, ], }; } if (providerId.startsWith(OPENAI_COMPATIBLE_PREFIX)) { return { title: t("openaiCompatible"), description: "", breadcrumbs: [ { label: t("providers"), href: "/dashboard/providers" }, { label: t("openaiCompatible"), providerId: "oai-cc" }, ], }; } if (providerId.startsWith(ANTHROPIC_COMPATIBLE_PREFIX)) { return { title: t("anthropicCompatible"), description: "", breadcrumbs: [ { label: t("providers"), href: "/dashboard/providers" }, { label: t("anthropicCompatible"), providerId: "anthropic-m" }, ], }; } } if (pathname.includes("/providers")) return { title: t("providers"), description: t("providerDescription"), breadcrumbs: [], }; if (pathname.includes("/combos")) return { title: t("combos"), description: t("comboDescription"), breadcrumbs: [] }; if (pathname.includes("/usage")) return { title: t("usage"), description: t("usageDescription"), breadcrumbs: [], }; if (pathname.includes("/analytics")) return { title: t("analytics"), description: t("analyticsDescription"), breadcrumbs: [], }; if (pathname.includes("/cli-tools")) return { title: t("cliTools"), description: t("cliToolsDescription"), breadcrumbs: [] }; if (pathname === "/dashboard") return { title: t("home"), description: t("homeDescription"), breadcrumbs: [] }; if (pathname.includes("/mcp")) return { title: t("mcp"), description: t("mcpDescription"), breadcrumbs: [] }; if (pathname.includes("/a2a")) return { title: t("a2a"), description: t("a2aDescription"), breadcrumbs: [] }; if (pathname.includes("/endpoint")) return { title: t("endpoint"), description: t("endpointDescription"), breadcrumbs: [] }; if (pathname.includes("/profile")) return { title: t("settings"), description: t("settingsDescription"), breadcrumbs: [] }; // Note: /themes page removed – theme settings live in /settings → AppearanceTab return { title: "", description: "", breadcrumbs: [] }; } export default function Header({ onMenuClick, showMenuButton = true }) { const pathname = usePathname(); const router = useRouter(); const isElectron = useIsElectron(); const t = useTranslations("header"); const { title, description, breadcrumbs } = usePageInfo(pathname); const isMacElectron = isElectron && typeof window !== "undefined" && window.electronAPI?.platform === "darwin"; const handleLogout = async () => { try { const res = await fetch("/api/auth/logout", { method: "POST" }); if (res.ok) { router.push("/login"); router.refresh(); } } catch (err) { console.error("Failed to logout:", err); } }; return (
{/* Mobile menu button */}
{showMenuButton && ( )}
{/* Page title with breadcrumbs - desktop */}
{breadcrumbs.length > 0 ? (
{breadcrumbs.map((crumb, index) => (
{index > 0 && ( chevron_right )} {crumb.href ? ( {crumb.label} ) : (
{crumb.image && ( {crumb.label} { e.currentTarget.style.display = "none"; }} /> )} {crumb.providerId && ( )}

{crumb.label}

)}
))}
) : title ? (

{title}

{description &&

{description}

}
) : null}
{/* Right actions */}
{/* Language selector */} {/* Theme toggle */} {/* Degradation & Token health */} {!isE2EMode && } {!isE2EMode && } {/* Logout button */}
); } Header.propTypes = { onMenuClick: PropTypes.func, showMenuButton: PropTypes.bool, };