"use client" import { useState, useEffect } from "react" import { Shield, ShieldCheck, ShieldX, ShieldQuestion, Pencil } from "lucide-react" import { cn } from "@/lib/utils" export type AntiCheatData = { antiCheatRelevant: boolean antiCheatName: string antiCheatStatus: "none" | "supported" | "unsupported" | "unknown" } interface PlatformSupportEntry { hardwareSlug: string antiCheatRelevant: boolean antiCheatStatus: "none" | "supported" | "unsupported" | "unknown" antiCheatName: string | null } interface AntiCheatStepProps { hardwareSlug: string platformSupport: PlatformSupportEntry[] value: AntiCheatData onChange: (data: AntiCheatData) => void } const statusConfig = { supported: { icon: ShieldCheck, label: "Supported", color: "border-green-500/30 bg-green-500/10", textColor: "text-green-400", message: "Anti-cheat works on Linux/SteamOS. Multiplayer should work.", }, unsupported: { icon: ShieldX, label: "Unsupported", color: "border-red-500/30 bg-red-500/10", textColor: "text-red-400", message: "Anti-cheat does not support Linux/SteamOS. Multiplayer may not work.", }, unknown: { icon: ShieldQuestion, label: "Unknown", color: "border-yellow-500/30 bg-yellow-500/10", textColor: "text-yellow-400", message: "Compatibility is unknown. Multiplayer may or may not work.", }, none: { icon: Shield, label: "None", color: "border-zinc-500/30 bg-zinc-500/10", textColor: "text-zinc-400", message: "No anti-cheat detected.", }, } as const export function AntiCheatStep({ hardwareSlug, platformSupport, value, onChange, }: AntiCheatStepProps) { const [isEditing, setIsEditing] = useState(false) // Find the best existing entry to prefill: // Prefer the entry for the currently selected hardware, // otherwise fall back to any entry with anti-cheat data. const hardwareEntry = platformSupport.find( (p) => p.hardwareSlug === hardwareSlug && p.antiCheatRelevant ) const anyEntry = platformSupport.find((p) => p.antiCheatRelevant) const existingEntry = hardwareEntry ?? anyEntry // Prefill once when the component mounts if the current value is the default useEffect(() => { if (existingEntry && !isEditing) { onChange({ antiCheatRelevant: existingEntry.antiCheatRelevant, antiCheatName: existingEntry.antiCheatName ?? "", antiCheatStatus: existingEntry.antiCheatStatus, }) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [hardwareSlug]) // re-prefill when hardware changes const relevant = value.antiCheatRelevant const currentConfig = statusConfig[value.antiCheatStatus] const CurrentIcon = currentConfig.icon return (

Anti-Cheat

Set the anti-cheat status for this game. This helps others know if multiplayer will work.

{/* Toggle: Has anti-cheat? */}
Game uses anti-cheat {relevant ? "Yes — select the anti-cheat name and compatibility below" : "No anti-cheat software detected in this game"}
{relevant && (
{/* Anti-cheat name */}
onChange({ ...value, antiCheatName: e.target.value }) } placeholder="e.g. Easy Anti-Cheat, BattlEye, Ricochet" className="w-full px-3 py-2 rounded-lg bg-background border border-border text-sm text-text placeholder:text-text/30 focus:outline-none focus:ring-2 focus:ring-primary/30" />
{/* Status radios */}
{( [ "supported", "unsupported", "unknown", ] as const ).map((status) => { const cfg = statusConfig[status] const Icon = cfg.icon const active = value.antiCheatStatus === status return ( ) })}
)} {/* Preview card */}

{relevant && value.antiCheatName ? value.antiCheatName : currentConfig.label}

{currentConfig.message}

) }