import { useState, useCallback } from "preact/hooks"; import { useT } from "../../../shared/i18n/context"; import { useProxyAssignments } from "../../../shared/hooks/use-proxy-assignments"; import { ProxyGroupList } from "../components/ProxyGroupList"; import { AccountTable } from "../components/AccountTable"; import { BulkActions } from "../components/BulkActions"; import { ImportExport } from "../components/ImportExport"; import { RuleAssign } from "../components/RuleAssign"; export function ProxySettings() { const t = useT(); const data = useProxyAssignments(); const [selectedGroup, setSelectedGroup] = useState(null); const [selectedIds, setSelectedIds] = useState>(new Set()); const [statusFilter, setStatusFilter] = useState("all"); const [showRuleAssign, setShowRuleAssign] = useState(false); // Single account proxy change (optimistic) const handleSingleProxyChange = useCallback( async (accountId: string, proxyId: string) => { await data.assignBulk([{ accountId, proxyId }]); }, [data.assignBulk], ); // Bulk assign all selected to a single proxy const handleBulkAssign = useCallback( async (proxyId: string) => { const assignments = Array.from(selectedIds).map((accountId) => ({ accountId, proxyId })); await data.assignBulk(assignments); setSelectedIds(new Set()); }, [selectedIds, data.assignBulk], ); // Even distribute selected across all active proxies const handleEvenDistribute = useCallback(async () => { const activeProxies = data.proxies.filter((p) => p.status === "active"); if (activeProxies.length === 0) return; const ids = Array.from(selectedIds); await data.assignRule(ids, "round-robin", activeProxies.map((p) => p.id)); setSelectedIds(new Set()); }, [selectedIds, data.proxies, data.assignRule]); // Rule-based assignment const handleRuleAssign = useCallback( async (rule: string, targetProxyIds: string[]) => { const ids = Array.from(selectedIds); await data.assignRule(ids, rule, targetProxyIds); setSelectedIds(new Set()); setShowRuleAssign(false); }, [selectedIds, data.assignRule], ); if (data.loading) { return (
Loading...
); } return (
{/* Top bar */}

{t("proxySettings")}

{t("proxySettingsDesc")}

{/* Main content */}
{/* Left sidebar — proxy groups */} {/* Right panel — account table */}
{/* Mobile group filter */}
{/* Bulk actions bar */} setShowRuleAssign(true)} /> {/* Rule assign modal */} {showRuleAssign && ( setShowRuleAssign(false)} /> )}
); }