"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 "@/shared/components"; import TokenHealthBadge from "./TokenHealthBadge"; import { OAUTH_PROVIDERS, APIKEY_PROVIDERS, FREE_PROVIDERS, OPENAI_COMPATIBLE_PREFIX, ANTHROPIC_COMPATIBLE_PREFIX, } from "@/shared/constants/providers"; const getPageInfo = (pathname) => { 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: "Providers", href: "/dashboard/providers" }, { label: providerInfo.name, image: `/providers/${providerInfo.id}.png` }, ], }; } if (providerId.startsWith(OPENAI_COMPATIBLE_PREFIX)) { return { title: "OpenAI Compatible", description: "", breadcrumbs: [ { label: "Providers", href: "/dashboard/providers" }, { label: "OpenAI Compatible", image: "/providers/oai-cc.png" }, ], }; } if (providerId.startsWith(ANTHROPIC_COMPATIBLE_PREFIX)) { return { title: "Anthropic Compatible", description: "", breadcrumbs: [ { label: "Providers", href: "/dashboard/providers" }, { label: "Anthropic Compatible", image: "/providers/anthropic-m.png" }, ], }; } } if (pathname.includes("/providers")) return { title: "Providers", description: "Manage your AI provider connections", breadcrumbs: [], }; if (pathname.includes("/combos")) return { title: "Combos", description: "Model combos with fallback", breadcrumbs: [] }; if (pathname.includes("/usage")) return { title: "Usage & Analytics", description: "Monitor your API usage, token consumption, and request logs", breadcrumbs: [], }; if (pathname.includes("/analytics")) return { title: "Analytics", description: "Charts, trends, and evaluation insights", breadcrumbs: [], }; if (pathname.includes("/cli-tools")) return { title: "CLI Tools", description: "Configure CLI tools", breadcrumbs: [] }; if (pathname === "/dashboard") return { title: "Home", description: "Welcome to OmniRoute", breadcrumbs: [] }; if (pathname.includes("/endpoint")) return { title: "Endpoint", description: "API endpoint configuration", breadcrumbs: [] }; if (pathname.includes("/profile")) return { title: "Settings", description: "Manage your preferences", breadcrumbs: [] }; return { title: "", description: "", breadcrumbs: [] }; }; export default function Header({ onMenuClick, showMenuButton = true }) { const pathname = usePathname(); const router = useRouter(); const { title, description, breadcrumbs } = getPageInfo(pathname); 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.label}

)}
))}
) : title ? (

{title}

{description &&

{description}

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