import { useRef } from "react"; import { Activity as ActivityIcon, Circle, Clock3, History as HistoryIcon, KeyRound, LayoutGrid, Play, Send, SlidersHorizontal, } from "lucide-react"; import type { LucideIcon } from "lucide-react"; import { Link } from "@/lib/router"; import { cn } from "@/lib/utils"; import { ROUTINE_SECTION_KEYS, type RoutineSectionKey, } from "./routine-sections/context"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; type NavItem = { key: RoutineSectionKey; label: string; icon: LucideIcon; }; type NavGroup = { label: string; items: NavItem[]; }; const NAV_GROUPS: NavGroup[] = [ { label: "Routine", items: [ { key: "overview", label: "Overview", icon: Circle }, { key: "triggers", label: "Triggers", icon: Clock3 }, { key: "variables", label: "Variables", icon: LayoutGrid }, { key: "secrets", label: "Secrets", icon: KeyRound }, { key: "delivery", label: "Delivery", icon: Send }, ], }, { label: "Operate", items: [ { key: "runs", label: "Runs", icon: Play }, { key: "activity", label: "Activity", icon: ActivityIcon }, { key: "history", label: "History", icon: HistoryIcon }, ], }, ]; const ALL_ITEMS: NavItem[] = NAV_GROUPS.flatMap((group) => group.items); export function RoutineSubSidebar({ activeSection, hrefFor, isSectionDirty, hasLiveRun, onNavigate, }: { activeSection: RoutineSectionKey; hrefFor: (section: RoutineSectionKey) => string; isSectionDirty: (section: RoutineSectionKey) => boolean; hasLiveRun: boolean; onNavigate: (section: RoutineSectionKey) => void; }) { const itemRefs = useRef>([]); const focusItem = (index: number) => { const clamped = (index + ALL_ITEMS.length) % ALL_ITEMS.length; itemRefs.current[clamped]?.focus(); onNavigate(ALL_ITEMS[clamped].key); }; const handleKeyDown = (event: React.KeyboardEvent, index: number) => { switch (event.key) { case "ArrowDown": event.preventDefault(); focusItem(index + 1); break; case "ArrowUp": event.preventDefault(); focusItem(index - 1); break; case "Home": event.preventDefault(); focusItem(0); break; case "End": event.preventDefault(); focusItem(ALL_ITEMS.length - 1); break; default: break; } }; let flatIndex = -1; return ( ); } /** Mobile section picker — collapses the sub-sidebar into a grouped ` { if (ROUTINE_SECTION_KEYS.includes(value as RoutineSectionKey)) { onNavigate(value as RoutineSectionKey); } }} > {NAV_GROUPS.map((group) => ( {group.label} {group.items.map((item) => ( {item.label} {isSectionDirty(item.key) ? ( ) : null} ))} ))} ); } export { ALL_ITEMS as ROUTINE_NAV_ITEMS };