import './rail.css';
import { Tooltip } from '@mantine/core';
import { IconAlertTriangle, IconHandStop } from '@tabler/icons-react';
import { NavLink as RouterLink, useLocation } from 'react-router-dom';
import { useBrand, useHealth, useKill, useRuns } from '../../api/hooks';
import { useAuth } from '../../auth/AuthContext';
import { useWaitsOnMe } from '../../waiting';
import { AccountMenu, INTEGRATIONS, LIBRARY, MAIN, SETTINGS, SETUP, type NavItem } from './AppSidebar';
import { envKind, useChosenEnv } from './EnvSwitcher';
function RailLink({ item, badge }: { item: NavItem; badge?: number }) {
const loc = useLocation();
const active = item.match ? item.match(loc.pathname) : loc.pathname === item.to || loc.pathname.startsWith(`${item.to}/`);
const name = badge ? `${item.label}, ${badge} waiting for you` : item.label;
return (
{item.icon}
{!!badge && {badge > 9 ? '9+' : badge}}
);
}
/** The app's navigation on a desktop: a narrow rail of icons (each named on hover and to screen readers), the runs
* waiting for you as a badge on Test runs, the emergency stop and a silent practice app as warnings, the account at the
* bottom. The environment switcher lives in the top bar. */
export function IconRail() {
const { can } = useAuth();
const brand = useBrand();
const runs = useRuns(40, 0);
const mine = useWaitsOnMe();
const kill = useKill();
const health = useHealth();
const env = useChosenEnv().pod;
const waiting = (runs.data?.items ?? []).filter(mine).length;
const name = brand.data?.product_name ?? 'Patchwise';
const items: NavItem[] = [...MAIN, ...LIBRARY, ...SETUP, ...(can('admin') ? [INTEGRATIONS, SETTINGS] : [])];
return (