"use client"; import * as React from "react"; import { useRouter } from "next/navigation"; import { ArrowDown, ArrowUp, Eraser, Plus, Save, X } from "lucide-react"; import { resetDomainStats, updateDomainPolicy, type AdminActionResult } from "@/actions/admin"; import { Button } from "@/components/ui/button"; import { NativeSelect } from "@/components/ui/input"; import { Field, Hint, Label } from "@/components/ui/label"; import { ActionButton, ResultMessage } from "./action-button"; const NETWORKS = ["datacenter", "residential", "isp", "mobile"] as const; export function DomainPolicyEditor({ domain, policy, availableKeys }: { domain: string; policy: { order?: string[]; force_network?: string } | null; availableKeys: string[] }) { const router = useRouter(); const [pending, start] = React.useTransition(); const [force, setForce] = React.useState(policy?.force_network ?? ""); const [order, setOrder] = React.useState(policy?.order ?? []); const [pick, setPick] = React.useState(""); const [result, setResult] = React.useState(null); const candidates = availableKeys.filter((k) => !order.includes(k)); const move = (i: number, d: -1 | 1) => setOrder((cur) => { const next = [...cur]; const j = i + d; if (j < 0 || j >= next.length) return cur; [next[i], next[j]] = [next[j]!, next[i]!]; return next; }); return (
{ e.preventDefault(); start(async () => { const r = await updateDomainPolicy(domain, { force_network: force || null, order }); setResult(r); if (r.ok) router.refresh(); }); }} > setForce(e.target.value)} className="w-[220px]"> {NETWORKS.map((n) => ( ))} Applies only when the customer asks for `network: "auto"`. Explicit network requests are never overridden.
Ordered list of `provider:network` keys. Pinned routes are tried first (in this order); unpinned candidates follow by score. {order.length ? (
    {order.map((k, i) => (
  1. {i + 1}. {k}
  2. ))}
) : (

No pinned routes — the engine orders candidates by score.

)}
setPick(e.target.value)} className="w-[260px]" aria-label="Route to pin"> {candidates.map((k) => ( ))}
); } export function ResetDomainStatsButton({ domain }: { domain: string }) { return ( resetDomainStats(domain)} confirm={{ title: `Reset learned stats for ${domain}?`, description: "Route statistics, block/captcha counters and the preferred route are cleared. The policy is kept. The router falls back to network priors until new data accumulates.", confirmLabel: "Reset stats" }} > Reset stats ); }