File size: 2,000 Bytes
cd8bd0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use client";

export type SourceId = "1proxy" | "proxifly" | "iplocate";

export const ALL_SOURCE_IDS: SourceId[] = ["1proxy", "proxifly", "iplocate"];

export const FREE_POOL_DISABLED_SOURCES_KEY = "freePool.disabledSources";

export function loadDisabledSources(): Set<SourceId> {
  try {
    const raw = globalThis.localStorage?.getItem(FREE_POOL_DISABLED_SOURCES_KEY);
    if (!raw) return new Set();
    const arr = JSON.parse(raw) as unknown[];
    return new Set(arr.filter((id): id is SourceId => ALL_SOURCE_IDS.includes(id as SourceId)));
  } catch {
    return new Set();
  }
}

export function saveDisabledSources(disabled: Set<SourceId>): void {
  try {
    globalThis.localStorage?.setItem(FREE_POOL_DISABLED_SOURCES_KEY, JSON.stringify([...disabled]));
  } catch {}
}

interface SourceToggleBarProps {
  disabledSources: Set<SourceId>;
  onToggle: (source: SourceId) => void;
}

const SOURCES: Array<{ id: SourceId; label: string }> = [
  { id: "1proxy", label: "1proxy" },
  { id: "proxifly", label: "Proxifly" },
  { id: "iplocate", label: "IPLocate" },
];

export default function SourceToggleBar({ disabledSources, onToggle }: SourceToggleBarProps) {
  return (
    <div className="flex gap-2 flex-wrap" role="group" aria-label="Toggle proxy sources">
      {SOURCES.map((s) => {
        const enabled = !disabledSources.has(s.id);
        return (
          <button
            key={s.id}
            className={`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-medium border transition-colors ${
              enabled
                ? "bg-primary/20 border-primary text-primary"
                : "border-border text-text-muted hover:border-primary/50"
            }`}
            onClick={() => onToggle(s.id)}
            aria-pressed={enabled}
          >
            <span
              className={`w-1.5 h-1.5 rounded-full ${enabled ? "bg-primary" : "bg-text-muted"}`}
            />
            {s.label}
          </button>
        );
      })}
    </div>
  );
}