"use client"; import { ArrowLeftRight, ChartPie, Ellipsis, House, Landmark, MessageCircle, Monitor, Moon, Sun } from "lucide-react"; import Link from "next/link"; import type { ComponentType } from "react"; import { usePathname, useRouter } from "next/navigation"; import { Suspense, useEffect, useState } from "react"; import { useAssistant } from "@/components/Assistant"; import { BookmarkButton, SavedList } from "@/components/Bookmarks"; import { DonateLink, DonatePrompt } from "@/components/Donate"; // Home is the three steps. Spending holds Budgets and Recurring as tabs, More holds the rest; every page keeps its own URL. type Icon = ComponentType<{ size?: number; strokeWidth?: number }>; const LINKS: { href: string; label: string; icon: Icon }[] = [ { href: "/", label: "Home", icon: House }, { href: "/spending", label: "Spending", icon: ChartPie }, { href: "/transactions", label: "Activity", icon: ArrowLeftRight }, { href: "/accounts", label: "Accounts", icon: Landmark }, { href: "/more", label: "More", icon: Ellipsis }, ]; const SPENDING = [{ href: "/spending", label: "Overview" }, { href: "/budgets", label: "Budgets" }, { href: "/recurring", label: "Recurring" }]; const PLAN = [{ href: "/plan", label: "Money plan" }, { href: "/optimize", label: "Optimize" }, { href: "/bonuses", label: "Bonuses" }, { href: "/cards", label: "Cards" }]; const under = (path: string, href: string) => (href === "/" ? path === "/" : path === href || path.startsWith(href + "/")); const tabsOf = (path: string) => [SPENDING, PLAN].find((g) => g.some((t) => under(path, t.href))); const sectionOf = (path: string) => (SPENDING.some((t) => under(path, t.href)) ? "/spending" : LINKS.find((l) => under(path, l.href))?.href ?? (tabsOf(path) || under(path, "/connect-ai") || under(path, "/debt") ? "/more" : undefined)); const TITLES: Record = { "/": "Home", "/transactions": "Activity", "/spending": "Spending", "/budgets": "Budgets", "/recurring": "Recurring", "/plan": "Money plan", "/optimize": "Optimize", "/bonuses": "Bonuses", "/cards": "Cards", "/accounts": "Accounts", "/accounts/add": "Add accounts", "/settings": "Settings", "/more": "More", "/debt": "Debt", "/connect-ai": "Connect your AI", "/go-live": "Use your real bank", }; export function Nav() { const path = usePathname(); const assistant = useAssistant(); const section = sectionOf(path); return ( <> ); } // The tab bar on top of Spending and Plan pages. Lives in the layout, so it stays put while a tab loads. // cards: the Cards tab applies in the user's country (countries.ts). export function SectionTabs({ cards = true }: { cards?: boolean }) { const path = usePathname(); const tabs = tabsOf(path)?.filter((t) => cards || t.href !== "/cards"); if (!tabs) return null; return ( ); } function PhoneBar({ section }: { section?: string }) { const assistant = useAssistant(); const cell = "flex flex-col items-center gap-0.5 text-[11px] py-1.5 rounded-xl"; return ( ); } // Tells the server the browser's time zone, so "today" and "this month" match the user's clock. Refreshes once when it changes. export function TimeZoneCookie() { const router = useRouter(); useEffect(() => { const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; if (!tz || document.cookie.split("; ").includes(`tz=${tz}`)) return; document.cookie = `tz=${tz}; path=/; max-age=31536000; samesite=lax`; router.refresh(); }, [router]); return null; } // today (YYYY-MM-DD) comes from the server (user's time zone) so Home's "October 2026" renders the same on server and client. export function PageTitle({ today }: { today: string }) { const path = usePathname(); const key = "/" + (path.split("/")[1] ?? ""); const title = TITLES[path] ?? TITLES[key] ?? ""; const month = new Date(today + "T00:00:00Z").toLocaleDateString("en-US", { month: "long", timeZone: "UTC" }); return (

{key === "/" ? <>{month} {today.slice(0, 4)} : title}

); } const THEMES = [["system", "System", Monitor], ["light", "Light", Sun], ["dark", "Dark", Moon]] as const; // System / Light / Dark. Saved in localStorage; layout.tsx applies it before paint. export function ThemeToggle() { const [theme, setTheme] = useState("system"); useEffect(() => setTheme(document.documentElement.dataset.theme ?? "system"), []); function pick(t: string) { setTheme(t); if (t === "system") delete document.documentElement.dataset.theme; else document.documentElement.dataset.theme = t; try { if (t === "system") localStorage.removeItem("theme"); else localStorage.setItem("theme", t); } catch {} } return (
{THEMES.map(([t, label, Icon]) => ( ))}
); }