"use client" import { useState, useEffect } from "react" import { motion, AnimatePresence } from "motion/react" import { Monitor, Gamepad2, Loader2 } from "lucide-react" interface HardwareDevice { slug: string name: string deviceType: string } export interface PlatformSupportItem { hardwareSlug: string isSupported: boolean protonStatus: "native" | "proton" | "unsupported" | "unknown" } interface NonSteamPlatformStepProps { value: PlatformSupportItem[] onChange: (value: PlatformSupportItem[]) => void } const PROTON_OPTIONS: { value: PlatformSupportItem["protonStatus"]; label: string }[] = [ { value: "native", label: "Native" }, { value: "proton", label: "Proton" }, { value: "unsupported", label: "Unsupported" }, { value: "unknown", label: "Unknown" }, ] export function NonSteamPlatformStep({ value, onChange }: NonSteamPlatformStepProps) { const [devices, setDevices] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { let cancelled = false async function fetchHardware() { try { setLoading(true) setError(null) const res = await fetch("/api/performance/hardware") if (!res.ok) throw new Error("Failed to load hardware") const data = await res.json() if (!cancelled) { setDevices(data.data || []) } } catch { if (!cancelled) { setError("Failed to load hardware devices") } } finally { if (!cancelled) { setLoading(false) } } } fetchHardware() return () => { cancelled = true } }, []) const getItem = (slug: string): PlatformSupportItem => { return ( value.find((v) => v.hardwareSlug === slug) || { hardwareSlug: slug, isSupported: false, protonStatus: "unknown", } ) } const updateItem = (slug: string, patch: Partial) => { const existing = value.find((v) => v.hardwareSlug === slug) let next: PlatformSupportItem[] if (existing) { next = value.map((v) => v.hardwareSlug === slug ? { ...v, ...patch } : v ) } else { next = [ ...value, { hardwareSlug: slug, isSupported: patch.isSupported ?? false, protonStatus: patch.protonStatus ?? "unknown", }, ] } onChange(next) } const toggleSupported = (slug: string) => { const item = getItem(slug) updateItem(slug, { isSupported: !item.isSupported }) } if (loading) { return (

Loading hardware devices...

) } if (error) { return (

{error}

) } return (

Platform Support

Select devices this game supports and its Proton status.

{devices.map((device) => { const item = getItem(device.slug) const Icon = device.deviceType === "console" ? Gamepad2 : Monitor return (

{device.name}

{device.deviceType}

{item.isSupported && (
{PROTON_OPTIONS.map((opt) => ( ))}
)}
) })} {devices.length === 0 && (

No hardware devices available

)}
) }