"use client"; import { useState } from "react"; import { useRouter, usePathname } from "next/navigation"; import { ReadingSettings } from "@/components/reading-settings"; import { HeaderSearchButton } from "@/components/header-search"; import { cn } from "@/lib/utils"; const SEARCH_RETURN_KEY = "spsays_from_search"; export function PageHeader({ children, sticky = false, className, }: { children: React.ReactNode; sticky?: boolean; className?: string; }) { const [searchExpanded, setSearchExpanded] = useState(false); const router = useRouter(); const pathname = usePathname(); // Read (and consume) the search-return flag once on first render. // The lazy initialiser runs exactly once; on the server // (typeof window === "undefined") it returns false. const [fromSearch, setFromSearch] = useState(() => { if (typeof window === "undefined") return false; try { if ( sessionStorage.getItem(SEARCH_RETURN_KEY) === "1" && !pathname.startsWith("/search") ) { sessionStorage.removeItem(SEARCH_RETURN_KEY); return true; } } catch { // sessionStorage unavailable } return false; }); return (
{/* Title / logo area — hidden on mobile when search is active */}
{fromSearch ? ( <> {/* Hide the page's own breadcrumb link (always the first ) */}
{children}
) : ( children )}
{/* Actions — expands to fill width on mobile when search is active */}
{/* Hide reading settings on mobile when search is active */}
); }