"use client"; import type { ReactNode } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { ChevronRight } from "lucide-react"; import { useI18n } from "@/i18n/i18n-context"; import { messages as zhMessages } from "@/i18n/locales/zh"; import type { MessageKey } from "@/i18n/i18n-context"; import { cn } from "@/lib/utils"; type SegmentSlug = keyof typeof zhMessages.header.segments; const SEGMENT_SLUGS = new Set(Object.keys(zhMessages.header.segments)); interface Crumb { label: string; href?: string; } function buildCrumbs( pathname: string, t: (key: MessageKey) => string, ): Crumb[] { // Detail-page sub-routes are wrapped by a DetailSidebar that already // surfaces entity context + a "返回列表" affordance. Suppress the // automatic breadcrumb there so we don't repeat the hierarchy in two // places (sidebar AND header). if ( /^\/knowledge-base\/[^/]+(?:\/.*)?$/.test(pathname) || /^\/memory\/[^/]+(?:\/.*)?$/.test(pathname) ) { return []; } const parts = pathname.split("/").filter(Boolean); if (parts.length === 0) return []; const crumbs: Crumb[] = []; let acc = ""; parts.forEach((raw, index) => { acc += `/${raw}`; const decoded = decodeURIComponent(raw); const label = SEGMENT_SLUGS.has(decoded) ? t(`header.segments.${decoded as SegmentSlug}`) : decoded; crumbs.push({ label, href: index < parts.length - 1 ? acc : undefined, }); }); return crumbs; } interface PageHeaderProps { title: ReactNode; description?: ReactNode; /** Hide the auto-derived breadcrumb above the title. */ hideBreadcrumb?: boolean; /** Action buttons rendered on the right side. */ children?: ReactNode; className?: string; } /** * Page-level header with a webUI-flavoured layout: small breadcrumb on top, * 20px h1 with optional description on the next line, optional action slot * on the right. Replaces the old separate BreadcrumbBar — by deriving the * crumbs from `usePathname()` we keep the same surface the dashboard had * while merging it into the page-header position webUI uses. */ export function PageHeader({ title, description, hideBreadcrumb, children, className, }: PageHeaderProps) { const pathname = usePathname() ?? "/"; const { t } = useI18n(); const crumbs = hideBreadcrumb ? [] : buildCrumbs(pathname, t); return (
{crumbs.length > 1 && ( )}

{title}

{description && (

{description}

)}
{children && (
{children}
)}
); }