import { IconBook, IconLanguage, IconLoader2, IconLogout, IconMenu2, IconMoon, IconPlayerPlay, IconPower, IconRefresh, IconSun, } from "@tabler/icons-react" import { Link } from "@tanstack/react-router" import * as React from "react" import { useTranslation } from "react-i18next" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog.tsx" import { Button } from "@/components/ui/button.tsx" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu.tsx" import { Separator } from "@/components/ui/separator.tsx" import { SidebarTrigger } from "@/components/ui/sidebar" import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip" import { useGateway } from "@/hooks/use-gateway.ts" import { useTheme } from "@/hooks/use-theme.ts" import { postLauncherDashboardLogout } from "@/api/launcher-auth" export function AppHeader() { const { i18n, t } = useTranslation() const { theme, toggleTheme } = useTheme() const { state: gwState, loading: gwLoading, canStart, startReason, restartRequired, start, restart, stop, error: gwError, } = useGateway() const isRunning = gwState === "running" const isStarting = gwState === "starting" const isRestarting = gwState === "restarting" const isStopping = gwState === "stopping" const isStopped = gwState === "stopped" || gwState === "unknown" const showNotConnectedHint = !isRestarting && !isStopping && canStart && (gwState === "stopped" || gwState === "error") const [showStopDialog, setShowStopDialog] = React.useState(false) const [showLogoutDialog, setShowLogoutDialog] = React.useState(false) const handleLogout = async () => { await postLauncherDashboardLogout() globalThis.location.assign("/launcher-login") } const handleGatewayToggle = () => { if (gwLoading || isRestarting || isStopping || (!isRunning && !canStart)) { return } if (isRunning) { setShowStopDialog(true) } else { void start() } } const handleGatewayRestart = () => { if (gwLoading || isRestarting || !restartRequired || !canStart) return void restart() } const confirmStop = () => { setShowStopDialog(false) stop() } return (
Logo
{/* Center prominent connection status */}
{showNotConnectedHint && (
{t("chat.notConnected")}
)}
{t("header.gateway.stopDialog.title")} {t("header.gateway.stopDialog.description")} {t("common.cancel")} {t("header.gateway.stopDialog.confirm")} {t("header.logout.tooltip")} {t("header.logout.description")} {t("common.cancel")} void handleLogout()}> {t("header.logout.confirm")}
{restartRequired && ( {t("header.gateway.restartRequired")} )} {/* Gateway Start/Stop */} {isRunning ? ( {gwError ?? t("header.gateway.action.stop")} ) : ( {/* Wrap in span so the tooltip still fires when the button is disabled */} {(gwError || (!canStart && startReason)) ? ( {gwError ?? startReason} ) : null} )} {/* Docs Link */} {/* Language Switcher */} i18n.changeLanguage("en")}> English i18n.changeLanguage("zh")}> 简体中文 {/* Theme Toggle */} {t("header.logout.tooltip")}
) }