import { useState, useCallback } from "preact/hooks"; import { useT } from "@shared/i18n/context"; import type { ProxyEntry } from "@shared/types"; interface RuleAssignProps { proxies: ProxyEntry[]; selectedCount: number; onAssign: (rule: string, targetProxyIds: string[]) => void; onClose: () => void; } export function RuleAssign({ proxies, selectedCount, onAssign, onClose }: RuleAssignProps) { const t = useT(); const [rule, setRule] = useState("round-robin"); const [targetIds, setTargetIds] = useState>( () => new Set(proxies.filter((p) => p.status === "active").map((p) => p.id)), ); const toggleTarget = useCallback((id: string) => { setTargetIds((prev) => { const next = new Set(prev); if (next.has(id)) { next.delete(id); } else { next.add(id); } return next; }); }, []); const handleApply = useCallback(() => { if (targetIds.size === 0) return; onAssign(rule, Array.from(targetIds)); }, [rule, targetIds, onAssign]); // Also include special values const allTargets = [ { id: "global", label: t("globalDefault"), status: "active" as const }, { id: "direct", label: t("directNoProxy"), status: "active" as const }, ...proxies.map((p) => ({ id: p.id, label: p.name, status: p.status })), ]; return (
e.stopPropagation()} >

{t("assignRuleTitle")}

{selectedCount} {t("accountsCount")} {t("selected")}

{/* Rule selection */}
{/* Target proxies */}
{allTargets.map((target) => ( ))}
{/* Actions */}
); }