import { ComputerRounded, TroubleshootRounded, HelpOutlineRounded, SvgIconComponent, } from "@mui/icons-material"; import { Box, Typography, Stack, Paper, Tooltip, alpha, useTheme, Fade, } from "@mui/material"; import { useState, useMemo, memo, FC } from "react"; import { useTranslation } from "react-i18next"; import ProxyControlSwitches from "@/components/shared/proxy-control-switches"; import { useSystemProxyState } from "@/hooks/use-system-proxy-state"; import { useSystemState } from "@/hooks/use-system-state"; import { useVerge } from "@/hooks/use-verge"; import { showNotice } from "@/services/notice-service"; const LOCAL_STORAGE_TAB_KEY = "clash-verge-proxy-active-tab"; interface TabButtonProps { isActive: boolean; onClick: () => void; icon: SvgIconComponent; label: string; hasIndicator?: boolean; } // Tab组件 const TabButton: FC = memo( ({ isActive, onClick, icon: Icon, label, hasIndicator = false }) => ( {label} {hasIndicator && ( )} ), ); interface TabDescriptionProps { description: string; tooltipTitle: string; } // 描述文本组件 const TabDescription: FC = memo( ({ description, tooltipTitle }) => ( {description} ), ); export const ProxyTunCard: FC = () => { const { t } = useTranslation(); const theme = useTheme(); const [activeTab, setActiveTab] = useState( () => localStorage.getItem(LOCAL_STORAGE_TAB_KEY) || "system", ); const { verge } = useVerge(); const { isTunModeAvailable } = useSystemState(); const { actualState: systemProxyActualState } = useSystemProxyState(); const { enable_tun_mode } = verge ?? {}; const handleError = (err: unknown) => { showNotice.error(err); }; const handleTabChange = (tab: string) => { setActiveTab(tab); localStorage.setItem(LOCAL_STORAGE_TAB_KEY, tab); }; const tabDescription = useMemo(() => { if (activeTab === "system") { return { text: systemProxyActualState ? t("home.components.proxyTun.status.systemProxyEnabled") : t("home.components.proxyTun.status.systemProxyDisabled"), tooltip: t("home.components.proxyTun.tooltips.systemProxy"), }; } else { return { text: !isTunModeAvailable ? t("home.components.proxyTun.status.tunModeServiceRequired") : enable_tun_mode ? t("home.components.proxyTun.status.tunModeEnabled") : t("home.components.proxyTun.status.tunModeDisabled"), tooltip: t("home.components.proxyTun.tooltips.tunMode"), }; } }, [ activeTab, systemProxyActualState, enable_tun_mode, isTunModeAvailable, t, ]); return ( handleTabChange("system")} icon={ComputerRounded} label={t("settings.sections.system.toggles.systemProxy")} hasIndicator={systemProxyActualState} /> handleTabChange("tun")} icon={TroubleshootRounded} label={t("settings.sections.system.toggles.tunMode")} hasIndicator={enable_tun_mode && isTunModeAvailable} /> ); };