import { useEffect, useMemo, useState, type ReactNode } from "react"; import { AppShell } from "@astryxdesign/core/AppShell"; import { Badge } from "@astryxdesign/core/Badge"; import { Button } from "@astryxdesign/core/Button"; import { CommandPalette } from "@astryxdesign/core/CommandPalette"; import { DropdownMenu } from "@astryxdesign/core/DropdownMenu"; import { HStack, Stack } from "@astryxdesign/core/Stack"; import { Icon } from "@astryxdesign/core/Icon"; import { Layout, LayoutContent, LayoutFooter } from "@astryxdesign/core/Layout"; import { useMediaQuery } from "@astryxdesign/core/hooks"; import { SideNav, SideNavItem, SideNavSection } from "@astryxdesign/core/SideNav"; import { Text } from "@astryxdesign/core/Text"; import { TextInput } from "@astryxdesign/core/TextInput"; import { TopNav } from "@astryxdesign/core/TopNav"; import { createStaticSource } from "@astryxdesign/core/Typeahead"; import { BellAlertIcon, ChatBubbleLeftRightIcon, ChartBarSquareIcon, CheckBadgeIcon, MagnifyingGlassIcon, QueueListIcon, ShieldCheckIcon, } from "@heroicons/react/24/outline"; import wordmark from "../../assets/brand/archie-wordmark.svg?url"; import darkWordmark from "../../assets/brand/archie-wordmark-dark.svg?url"; export type Area = "Composer" | "Runs" | "Events" | "Governance" | "Reports"; type ShellFrameProps = { activeArea: Area; pendingCount: number; onNavigate: (area: Area) => void; dock?: ReactNode; children: ReactNode; }; const navigation = [ { title: "Work", items: [ { label: "Composer", icon: ChatBubbleLeftRightIcon }, { label: "Runs", icon: QueueListIcon }, { label: "Events", icon: BellAlertIcon }, ], }, { title: "Control", items: [ { label: "Governance", icon: ShieldCheckIcon }, { label: "Reports", icon: ChartBarSquareIcon }, ], }, ] satisfies Array<{ title: string; items: Array<{ label: Area; icon: typeof ChatBubbleLeftRightIcon }>; }>; type Command = { id: "composer" | "runs" | "events" | "governance" | "reports"; label: string; }; const commands: Command[] = [ { id: "composer", label: "Composer" }, { id: "runs", label: "Runs" }, { id: "events", label: "Events" }, { id: "governance", label: "Governance" }, { id: "reports", label: "Reports" }, ]; export function ShellFrame({ activeArea, pendingCount, onNavigate, dock, children, }: ShellFrameProps) { const [isPaletteOpen, setIsPaletteOpen] = useState(false); const [isMobileNavOpen, setIsMobileNavOpen] = useState(false); const source = useMemo(() => createStaticSource(commands), []); const hasInlineNavigation = useMediaQuery("(min-width: 768px)"); const prefersDark = useMediaQuery("(prefers-color-scheme: dark)"); useEffect(() => { function openPalette(event: KeyboardEvent) { if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") { event.preventDefault(); setIsPaletteOpen(true); } } window.addEventListener("keydown", openPalette); return () => window.removeEventListener("keydown", openPalette); }, []); useEffect(() => { setIsMobileNavOpen(false); }, [activeArea]); function renderNavigation() { return ( {navigation.map((section) => ( {section.items.map((item) => ( navigate(item.label)} endContent={ item.label === "Runs" && pendingCount > 0 ? ( ) : undefined } /> ))} ))} ); } function navigate(area: Area) { setIsMobileNavOpen(false); onNavigate(area); window.setTimeout(() => setIsMobileNavOpen(false), 0); } function chooseCommand(value: Command) { setIsPaletteOpen(false); navigate( value.id === "composer" ? "Composer" : value.id === "runs" ? "Runs" : value.id === "events" ? "Events" : value.id === "governance" ? "Governance" : "Reports", ); } return ( <> } startContent={ }, { type: "divider" }, { label: "Instance settings", onClick: () => navigate("Governance") }, ]} /> } endContent={ {hasInlineNavigation && ( setIsPaletteOpen(true)}> setIsPaletteOpen(true)} /> )}