"use client"; import { useState, useEffect } from "react"; import PropTypes from "prop-types"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { cn } from "@/shared/utils/cn"; import { APP_CONFIG } from "@/shared/constants/config"; import Button from "./Button"; import { ConfirmModal } from "./Modal"; const navItems = [ { href: "/dashboard/endpoint", label: "Endpoint", icon: "api" }, { href: "/dashboard/providers", label: "Providers", icon: "dns" }, { href: "/dashboard/combos", label: "Combos", icon: "layers" }, { href: "/dashboard/usage", label: "Usage", icon: "bar_chart" }, { href: "/dashboard/cli-tools", label: "CLI Tools", icon: "terminal" }, ]; // Debug items (only show when ENABLE_REQUEST_LOGS=true) const debugItems = [ // { href: "/dashboard/translator", label: "Translator", icon: "translate" }, { href: "/dashboard/console-log", label: "Console Log", icon: "terminal" }, ]; const systemItems = [ { href: "/dashboard/profile", label: "Settings", icon: "settings" }, ]; export default function Sidebar({ onClose }) { const pathname = usePathname(); const [showShutdownModal, setShowShutdownModal] = useState(false); const [isShuttingDown, setIsShuttingDown] = useState(false); const [isDisconnected, setIsDisconnected] = useState(false); const [updateInfo, setUpdateInfo] = useState(null); // Lazy check for new npm version on mount useEffect(() => { fetch("/api/version") .then(res => res.json()) .then(data => { if (data.hasUpdate) setUpdateInfo(data); }) .catch(() => {}); }, []); const isActive = (href) => { if (href === "/dashboard/endpoint") { return pathname === "/dashboard" || pathname.startsWith("/dashboard/endpoint"); } return pathname.startsWith(href); }; const handleShutdown = async () => { setIsShuttingDown(true); try { await fetch("/api/shutdown", { method: "POST" }); } catch (e) { // Expected to fail as server shuts down; ignore error } setIsShuttingDown(false); setShowShutdownModal(false); setIsDisconnected(true); }; return ( <> {/* Shutdown Confirmation Modal */} setShowShutdownModal(false)} onConfirm={handleShutdown} title="Close Proxy" message="Are you sure you want to close the proxy server?" confirmText="Close" cancelText="Cancel" variant="danger" loading={isShuttingDown} /> {/* Disconnected Overlay */} {isDisconnected && (
power_off

Server Disconnected

The proxy server has been stopped.

)} ); } Sidebar.propTypes = { onClose: PropTypes.func, };