"use client" import { useState, useEffect } from "react" import { Shield, ShieldCheck, ShieldX, ShieldQuestion } 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] = 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 (
Set the anti-cheat status for this game. This helps others know if multiplayer will work.
{currentConfig.message}