export type WireGuardTab = "interfaces" | "peers" | "cli" export type WireGuardStatus = "all" | "up" | "down" const tabs = ["interfaces", "peers", "cli"] const statuses = ["all", "up", "down"] export function readWireGuardUrl(params: URLSearchParams) { const tab = params.get("tab") ?? "interfaces", status = params.get("status") ?? "all", search = params.get("q") ?? "" let error: string | null = null if (["tab", "status", "q"].some(key => params.getAll(key).length > 1)) error = "В ссылке повторяются фильтры WireGuard." else if (!tabs.includes(tab)) error = "В ссылке указана неизвестная вкладка WireGuard." else if (!statuses.includes(status)) error = "В ссылке указан неизвестный статус WireGuard." else if (search.length > 200) error = "Поиск WireGuard в ссылке слишком длинный." return { tab: (tabs.includes(tab) ? tab : "interfaces") as WireGuardTab, status: (statuses.includes(status) ? status : "all") as WireGuardStatus, search, error } } export function patchWireGuardUrl(params: URLSearchParams, changes: Record) { const next = new URLSearchParams(params) for (const [key, value] of Object.entries(changes)) if (!value) next.delete(key); else next.set(key, value) return "/wireguard" + (next.size ? "?" + next.toString() : "") }