"use client";
/**
* SiteBottomNav — mobile-only bottom tab bar.
*
* Four items: Home · Search · Kautilya · Account.
* Mirrors the Instagram pattern — fixed to the viewport bottom, full
* width, equal-width tabs, the active tab uses the primary color.
*
* Hidden on md+ — desktop uses SiteSidebar.
*/
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Home, MessageCircle, Search, User as UserIcon } from "lucide-react";
import {
NavUnreadBadge,
useChatUnread,
} from "@/components/layout/nav-unread-badge";
import { useAuth } from "@/components/auth/auth-provider";
import { useHidesAppChrome } from "@/lib/use-chrome-visibility";
import { cn } from "@/lib/utils";
type Item = {
/** Tab label, used for the aria-label. Bottom nav is icon-only. */
label: string;
href: string;
icon: React.ReactNode;
matchPrefixes?: string[];
};
export function SiteBottomNav() {
const pathname = usePathname();
const hidden = useHidesAppChrome();
const { user } = useAuth();
// Read here rather than inside the badge so the count can also reach the
// link's accessible name — the badge itself is decorative.
const chatUnread = useChatUnread();
const items: Item[] = [
{ href: "/", label: "Home", icon: },
{
href: "/search",
label: "Search",
icon: ,
// Search is the knowledgebase entry point too — keep the tab lit
// while the user is reading anywhere in the library.
matchPrefixes: [
"/search",
"/books",
"/letters",
"/transcriptions",
"/essays",
"/glossary",
"/journals",
"/magazines",
"/other-documents",
"/disciples",
],
},
{
href: "/chats",
label: "Chat",
icon: ,
},
{
href: user ? "/u/me" : "/login",
label: user ? "You" : "Sign in",
// Show the user's uploaded avatar when available so the nav
// feels personalized. Falls back to the generic person glyph
// for anonymous viewers and signed-in users who haven't
// uploaded a picture yet. The avatar circle is slightly larger
// (size-6 vs the size-5 icons elsewhere) so it reads as an
// identifying glyph rather than fading in with the other tabs.
icon: user?.avatar_url ? (
) : (
),
matchPrefixes: ["/u/me", "/login", "/signup"],
},
];
function isActive(item: Item): boolean {
if (item.matchPrefixes) {
return item.matchPrefixes.some((p) =>
p === "/" ? pathname === "/" : pathname.startsWith(p),
);
}
if (item.href === "/") return pathname === "/";
return pathname === item.href || pathname.startsWith(`${item.href}/`);
}
// A chat thread owns the bottom edge — its composer lives there.
if (hidden) return null;
return (
);
}