"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 (
{/* Layout strategy: - Mobile: actions float to the right so the title text wraps around them on the first line and uses the FULL container width on every subsequent line (which is what `pr-*` cannot achieve since padding applies to all lines). - Desktop (md+): standard flex row so title and actions sit side-by-side. */}
{/* Actions — float on mobile (rendered first so float works correctly), inline flex on desktop. Order doesn't matter visually on desktop because the parent's `justify-between` places them at the end. */}
{/* Hide reading settings on mobile when search is active */}
{/* Title / logo area — hidden on mobile when search is active */}
{fromSearch ? ( <> {/* Hide the page's own breadcrumb link (always the first ) */}
{children}
) : ( children )}
); }