import { useState } from "react"; import { Server, Activity, Zap, Globe, ShieldAlert } from "lucide-react"; import { motion } from "framer-motion"; import { useTranslation } from "react-i18next"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Badge } from "@/components/ui/badge"; import { ProxyPanel } from "@/components/proxy"; import { AutoFailoverConfigPanel } from "@/components/proxy/AutoFailoverConfigPanel"; import { FailoverQueueManager } from "@/components/proxy/FailoverQueueManager"; import { RectifierConfigPanel } from "@/components/settings/RectifierConfigPanel"; import { GlobalProxySettings } from "@/components/settings/GlobalProxySettings"; import { ConfirmDialog } from "@/components/ConfirmDialog"; import { ToggleRow } from "@/components/ui/toggle-row"; import { useProxyStatus } from "@/hooks/useProxyStatus"; import type { SettingsFormState } from "@/hooks/useSettings"; interface ProxyTabContentProps { settings: SettingsFormState; onAutoSave: (updates: Partial) => Promise; } export function ProxyTabContent({ settings, onAutoSave, }: ProxyTabContentProps) { const { t } = useTranslation(); const [showProxyConfirm, setShowProxyConfirm] = useState(false); const [showFailoverConfirm, setShowFailoverConfirm] = useState(false); const { isRunning, startProxyServer, stopWithRestore, isPending: isProxyPending, } = useProxyStatus(); const handleToggleProxy = async (checked: boolean) => { try { if (!checked) { await stopWithRestore(); } else if (!settings?.proxyConfirmed) { setShowProxyConfirm(true); } else { await startProxyServer(); } } catch (error) { console.error("Toggle proxy failed:", error); } }; const handleProxyConfirm = async () => { setShowProxyConfirm(false); try { await onAutoSave({ proxyConfirmed: true }); await startProxyServer(); } catch (error) { console.error("Proxy confirm failed:", error); } }; const handleFailoverToggleChange = (checked: boolean) => { if (checked && !settings?.failoverConfirmed) { setShowFailoverConfirm(true); } else { void onAutoSave({ enableFailoverToggle: checked }); } }; const handleFailoverConfirm = async () => { setShowFailoverConfirm(false); try { await onAutoSave({ failoverConfirmed: true, enableFailoverToggle: true }); } catch (error) { console.error("Failover confirm failed:", error); } }; return ( {/* Local Proxy */}

{t("settings.advanced.proxy.title")}

{t("settings.advanced.proxy.description")}

{isRunning ? t("settings.advanced.proxy.running") : t("settings.advanced.proxy.stopped")}
onAutoSave({ enableLocalProxy: checked }) } onToggleProxy={handleToggleProxy} isProxyPending={isProxyPending} />
{/* Auto Failover */}

{t("settings.advanced.failover.title")}

{t("settings.advanced.failover.description")}

} title={t("settings.advanced.proxy.enableFailoverToggle")} description={t( "settings.advanced.proxy.enableFailoverToggleDescription", )} checked={settings?.enableFailoverToggle ?? false} onCheckedChange={handleFailoverToggleChange} /> {!isRunning && (

{t("proxy.failover.proxyRequired", { defaultValue: "需要先启动代理服务才能配置故障转移", })}

)} Claude Codex Gemini

{t("proxy.failoverQueue.title")}

{t("proxy.failoverQueue.description")}

{t("proxy.failoverQueue.title")}

{t("proxy.failoverQueue.description")}

{t("proxy.failoverQueue.title")}

{t("proxy.failoverQueue.description")}

{/* Rectifier */}

{t("settings.advanced.rectifier.title")}

{t("settings.advanced.rectifier.description")}

{/* Global Outbound Proxy */}

{t("settings.advanced.globalProxy.title")}

{t("settings.advanced.globalProxy.description")}

void handleProxyConfirm()} onCancel={() => setShowProxyConfirm(false)} /> void handleFailoverConfirm()} onCancel={() => setShowFailoverConfirm(false)} />
); }