"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { SettingsIcon, Gamepad2Icon } from "lucide-react" interface HardwareDevice { slug: string name: string deviceType: string } interface PlatformSupportEntry { hardwareSlug: string isSupported: boolean protonStatus: string } interface GameData { id: string title: string | null developer: string | null publisher: string | null description: string | null source: string storeUrl: string | null headerImage: string | null capsuleImage: string | null genres: string[] | null releaseDate: string | null createdBy: string | null } interface Props { game: GameData platformSupport: PlatformSupportEntry[] hardwareList: HardwareDevice[] isOwner: boolean isAdmin: boolean } export function NonSteamEditForm({ game, platformSupport, hardwareList, isOwner, isAdmin }: Props) { const router = useRouter() const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [title, setTitle] = useState(game.title ?? "") const [developer, setDeveloper] = useState(game.developer ?? "") const [publisher, setPublisher] = useState(game.publisher ?? "") const [description, setDescription] = useState(game.description ?? "") const [storeUrl, setStoreUrl] = useState(game.storeUrl ?? "") const [headerImage, setHeaderImage] = useState(game.headerImage ?? "") const [capsuleImage, setCapsuleImage] = useState(game.capsuleImage ?? "") const [genresStr, setGenresStr] = useState(game.genres?.join(", ") ?? "") const [releaseDate, setReleaseDate] = useState(game.releaseDate ?? "") const [platforms, setPlatforms] = useState(platformSupport) const canEdit = isOwner || isAdmin const handleTogglePlatform = (slug: string) => { setPlatforms(prev => { const existing = prev.find(p => p.hardwareSlug === slug) if (existing) { return prev.filter(p => p.hardwareSlug !== slug) } return [...prev, { hardwareSlug: slug, isSupported: true, protonStatus: "unknown" }] }) } const handleProtonChange = (slug: string, protonStatus: string) => { setPlatforms(prev => prev.map(p => p.hardwareSlug === slug ? { ...p, protonStatus } : p) ) } const handleSubmit = async () => { setLoading(true) setError(null) try { const res = await fetch(`/api/games/${game.id}/manual`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: title.trim(), developer: developer.trim() || null, publisher: publisher.trim() || null, description: description.trim() || null, storeUrl: storeUrl.trim() || null, headerImage: headerImage.trim() || null, capsuleImage: capsuleImage.trim() || null, genres: genresStr.split(",").map(g => g.trim()).filter(Boolean), releaseDate: releaseDate.trim() || null, }), }) if (!res.ok) { const data = await res.json() throw new Error(data.error || "Failed to update game") } router.push(`/game/${game.id}`) router.refresh() } catch (err: unknown) { setError(err instanceof Error ? err.message : "Failed to update game") } finally { setLoading(false) } } if (!canEdit) { return (

Only the creator or an admin can edit this game.

) } return (
{/* Basic Info */}

Basic Info

setTitle(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-border bg-text/5 text-text text-sm placeholder:text-text/40 outline-none focus:border-primary" />
setDeveloper(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-border bg-text/5 text-text text-sm placeholder:text-text/40 outline-none focus:border-primary" />
setPublisher(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-border bg-text/5 text-text text-sm placeholder:text-text/40 outline-none focus:border-primary" />
setStoreUrl(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-border bg-text/5 text-text text-sm placeholder:text-text/40 outline-none focus:border-primary" />