"use client"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { ProBadge } from "@/components/ui/pro-badge"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import type { WayfernConfig, WayfernFingerprintConfig, WayfernOS, } from "@/types"; interface WayfernConfigFormProps { config: WayfernConfig; onConfigChange: (key: keyof WayfernConfig, value: unknown) => void; className?: string; isCreating?: boolean; forceAdvanced?: boolean; readOnly?: boolean; crossOsUnlocked?: boolean; limitedMode?: boolean; } const isFingerprintEditingDisabled = (config: WayfernConfig): boolean => { return config.randomize_fingerprint_on_launch === true; }; const getCurrentOS = (): WayfernOS => { if (typeof navigator === "undefined") return "linux"; const platform = navigator.platform.toLowerCase(); if (platform.includes("win")) return "windows"; if (platform.includes("mac")) return "macos"; return "linux"; }; const osLabels: Record = { windows: "Windows", macos: "macOS", linux: "Linux", android: "Android", ios: "iOS", }; export function WayfernConfigForm({ config, onConfigChange, className = "", isCreating = false, forceAdvanced = false, readOnly = false, crossOsUnlocked = false, limitedMode = false, }: WayfernConfigFormProps) { const { t } = useTranslation(); const [activeTab, setActiveTab] = useState( forceAdvanced ? "manual" : "automatic", ); const [fingerprintConfig, setFingerprintConfig] = useState({}); const [currentOS] = useState(getCurrentOS); const selectedOS = config.os || currentOS; useEffect(() => { if (isCreating && typeof window !== "undefined") { const screenWidth = window.screen.width; const screenHeight = window.screen.height; if (!config.screen_max_width) { onConfigChange("screen_max_width", screenWidth); } if (!config.screen_max_height) { onConfigChange("screen_max_height", screenHeight); } } }, [ isCreating, config.screen_max_width, config.screen_max_height, onConfigChange, ]); useEffect(() => { if (config.fingerprint) { try { const parsed = JSON.parse( config.fingerprint, ) as WayfernFingerprintConfig; setFingerprintConfig(parsed); } catch (error) { console.error("Failed to parse fingerprint config:", error); setFingerprintConfig({}); } } else { setFingerprintConfig({}); } }, [config.fingerprint]); const updateFingerprintConfig = ( key: keyof WayfernFingerprintConfig, value: unknown, ) => { const newConfig = { ...fingerprintConfig }; if ( value === undefined || value === "" || (Array.isArray(value) && value.length === 0) ) { delete newConfig[key]; } else { (newConfig as Record)[key] = value; } setFingerprintConfig(newConfig); try { const jsonString = JSON.stringify(newConfig); onConfigChange("fingerprint", jsonString); } catch (error) { console.error("Failed to serialize fingerprint config:", error); } }; const isAutoLocationEnabled = config.geoip !== false; const handleAutoLocationToggle = (enabled: boolean) => { if (enabled) { onConfigChange("geoip", true); } else { onConfigChange("geoip", false); } }; const isEditingDisabled = isFingerprintEditingDisabled(config) || readOnly; const renderAdvancedForm = () => (
{/* Operating System Selection */}
{selectedOS !== currentOS && crossOsUnlocked && ( {t("fingerprint.crossOsWarning")} )}
{/* Randomize Fingerprint Option */}
onConfigChange("randomize_fingerprint_on_launch", checked) } disabled={readOnly} />

{t("fingerprint.generateRandomDescription")}

{/* Automatic Location Configuration */}
{!limitedMode && (isEditingDisabled ? ( {readOnly ? t("fingerprint.editingDisabledRunning") : t("fingerprint.editingDisabledRandomized")} ) : ( {t("fingerprint.basicWarning")} ))}
{/* User Agent and Platform */}
updateFingerprintConfig( "userAgent", e.target.value || undefined, ) } placeholder="Mozilla/5.0..." />
updateFingerprintConfig( "platform", e.target.value || undefined, ) } placeholder="e.g., Win32, MacIntel, Linux x86_64" />
updateFingerprintConfig( "platformVersion", e.target.value || undefined, ) } placeholder="e.g., 10.0.0" />
updateFingerprintConfig( "brand", e.target.value || undefined, ) } placeholder="e.g., Google Chrome" />
updateFingerprintConfig( "brandVersion", e.target.value || undefined, ) } placeholder="e.g., 143" />
{/* Hardware Properties */}
updateFingerprintConfig( "hardwareConcurrency", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 8" />
updateFingerprintConfig( "maxTouchPoints", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 0" />
updateFingerprintConfig( "deviceMemory", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 8" />
{/* Screen Properties */}
updateFingerprintConfig( "screenWidth", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1920" />
updateFingerprintConfig( "screenHeight", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1080" />
updateFingerprintConfig( "devicePixelRatio", e.target.value ? parseFloat(e.target.value) : undefined, ) } placeholder="e.g., 1.0" />
updateFingerprintConfig( "screenAvailWidth", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1920" />
updateFingerprintConfig( "screenAvailHeight", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1040" />
updateFingerprintConfig( "screenColorDepth", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 24" />
{/* Window Properties */}
updateFingerprintConfig( "windowOuterWidth", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1920" />
updateFingerprintConfig( "windowOuterHeight", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1040" />
updateFingerprintConfig( "windowInnerWidth", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 1920" />
updateFingerprintConfig( "windowInnerHeight", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 940" />
updateFingerprintConfig( "screenX", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 0" />
updateFingerprintConfig( "screenY", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 0" />
{/* Language & Locale */}
updateFingerprintConfig( "language", e.target.value || undefined, ) } placeholder="e.g., en-US" />
{ if (!e.target.value) { updateFingerprintConfig("languages", undefined); return; } try { const parsed = JSON.parse(e.target.value); if (Array.isArray(parsed)) { updateFingerprintConfig("languages", parsed); } } catch { // Invalid JSON, keep current value } }} placeholder='["en-US", "en"]' />
{/* Timezone and Geolocation */}

{t("fingerprint.timezoneGeolocationDescription")}

updateFingerprintConfig( "timezone", e.target.value || undefined, ) } placeholder="e.g., America/New_York" />
updateFingerprintConfig( "timezoneOffset", e.target.value ? parseInt(e.target.value, 10) : undefined, ) } placeholder="e.g., 300 for EST (UTC-5)" />
updateFingerprintConfig( "latitude", e.target.value ? parseFloat(e.target.value) : undefined, ) } placeholder="e.g., 40.7128" />
updateFingerprintConfig( "longitude", e.target.value ? parseFloat(e.target.value) : undefined, ) } placeholder="e.g., -74.0060" />
updateFingerprintConfig( "accuracy", e.target.value ? parseFloat(e.target.value) : undefined, ) } placeholder="e.g., 100" />
{/* WebGL Properties */}
updateFingerprintConfig( "webglVendor", e.target.value || undefined, ) } placeholder="e.g., Intel" />
updateFingerprintConfig( "webglRenderer", e.target.value || undefined, ) } placeholder="e.g., Intel(R) HD Graphics" />
{/* WebGL Parameters (JSON) */}