import type { ReactNode } from "react";
import { KeyRound, LayoutDashboard, Link2, LogOut, PanelsTopLeft, ShieldCheck } from "lucide-react";
import type { Me } from "../../shared/api-types.js";
import { ThemeCycleButton, ThemeSwitch } from "../components/ThemeToggle.js";
import { Button } from "../components/ui/button.js";
import { Link } from "../components/ui/misc.js";
import { cx } from "../lib/cx.js";
import type { Route } from "../router.js";
type Section = "overview" | "links" | "pages" | "tokens" | "admin";
function sectionOf(route: Route): Section | null {
switch (route.name) {
case "overview":
case "tokens":
case "admin":
return route.name;
case "adminUser":
return "admin";
case "list":
case "detail":
// Other users' pages are opened from Administration and stay in that section.
if (route.name === "detail" && route.owner) return "admin";
return route.kind === "redirect" ? "links" : "pages";
default:
return null;
}
}
const NAV: { id: Section; label: string; short: string; to: string; icon: ReactNode; adminOnly?: boolean }[] = [
{ id: "overview", label: "Overview", short: "Overview", to: "/~/", icon:
short
);
}
function UserAvatar({ username }: { username: string }) {
return (
{username.charAt(0)}
);
}
export function Shell({ me, route, onLogout, children }: { me: Me; route: Route; onLogout: () => void; children: ReactNode }) {
const active = sectionOf(route);
const items = NAV.filter((n) => !n.adminOnly || me.isAdmin);
return (