"use client"; import { useEffect, useState, type ReactNode } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import clsx from "clsx"; import { LogOut, Menu, MoreHorizontal, X } from "lucide-react"; import { useAuth } from "@/lib/auth"; import { MOBILE_TABS, NAV } from "./nav"; function normalize(p: string | null): string { if (!p) return "/"; const s = p.endsWith("/") ? p : p + "/"; return s; } function isCurrent(href: string, path: string): boolean { if (href === "/") return path === "/"; return path.startsWith(href); } export function Shell({ children }: { children: ReactNode }) { const { me, loading, logout, isOwner } = useAuth(); const pathname = normalize(usePathname()); const [open, setOpen] = useState(false); const isLogin = pathname === "/login/"; useEffect(() => setOpen(false), [pathname]); if (isLogin) return
{children}
; const isPublicPage = pathname === "/" || pathname === "/docs/"; if (!loading && (!me || !me.mfa_passed) && isPublicPage) { return (
FinData OS
{children}
); } if (loading || !me || !me.mfa_passed) { return (
{loading ? "Checking session…" : "Redirecting to sign-in…"}
); } const items = NAV.filter((n) => !n.owner || isOwner); const groups: { key: "data" | "ops" | "system"; label: string }[] = [ { key: "data", label: "Data" }, { key: "ops", label: "Operations" }, { key: "system", label: "System" }, ]; const tabs = items.filter((n) => MOBILE_TABS.includes(n.href)).slice(0, 4); const NavList = ( ); const Account = (
{me.email}
{me.role}
); return (
{/* Sidebar (desktop) */} {/* Top bar (mobile/tablet) */}
FinData OS
{/* Drawer */} {open && (
{NavList}
{Account}
)} {/* Content */}
{children}
{/* Bottom tab bar (mobile) */} ); } function Logo() { return ( ); }