"use client"; import { invoke } from "@tauri-apps/api/core"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { LoadingButton } from "@/components/loading-button"; import MultipleSelector, { type Option } from "@/components/multiple-selector"; 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 { CamoufoxConfig, CamoufoxFingerprintConfig, CamoufoxOS, } from "@/types"; interface SharedCamoufoxConfigFormProps { config: CamoufoxConfig; onConfigChange: (key: keyof CamoufoxConfig, value: unknown) => void; className?: string; isCreating?: boolean; // Flag to indicate if this is for creating a new profile forceAdvanced?: boolean; // Force advanced mode (for editing) readOnly?: boolean; // Flag to indicate if the form should be read-only browserType?: "camoufox" | "wayfern"; // Browser type to customize form options crossOsUnlocked?: boolean; // Allow selecting non-current OS (paid feature) limitedMode?: boolean; // Blur and disable advanced fields while keeping basic options accessible profileVersion?: string; profileBrowser?: string; } // Determine if fingerprint editing should be disabled const isFingerprintEditingDisabled = (config: CamoufoxConfig): boolean => { return config.randomize_fingerprint_on_launch === true; }; // Detect the current operating system const getCurrentOS = (): CamoufoxOS => { 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"; }; // OS display labels const osLabels: Record = { windows: "Windows", macos: "macOS", linux: "Linux", }; // Component for editing nested objects like webGl:parameters interface ObjectEditorProps { value: Record | undefined; onChange: (value: Record | undefined) => void; title: string; readOnly?: boolean; } function ObjectEditor({ value, onChange, title, readOnly = false, }: ObjectEditorProps) { const [jsonString, setJsonString] = useState(""); useEffect(() => { setJsonString(JSON.stringify(value || {}, null, 2)); }, [value]); const handleChange = (newValue: string) => { if (readOnly) return; setJsonString(newValue); try { if (newValue.trim() === "" || newValue.trim() === "{}") { onChange(undefined); // Treat empty objects as undefined return; } const parsed = JSON.parse(newValue); if ( typeof parsed === "object" && parsed !== null && Object.keys(parsed).length === 0 ) { onChange(undefined); return; } onChange(parsed as Record); } catch (err) { console.warn("Invalid JSON:", err); } }; return (