import { useState } from 'react' import { AdminTable, type Column } from '../../components/admin/AdminTable' import { GameFormModal } from '../../components/admin/GameFormModal' import { useGames } from '../../hooks/useGames' import { useCreateGame, useUpdateGame, useDeleteGame } from '../../hooks/useAdmin' import { exportGames } from '../../api/admin' import { downloadJson } from '../../utils/download' import type { Game, CreateGameInput, UpdateGameInput } from '../../types' export function AdminGames() { const { data: games = [], isLoading } = useGames() const createGame = useCreateGame() const updateGame = useUpdateGame() const deleteGame = useDeleteGame() const [showCreate, setShowCreate] = useState(false) const [editing, setEditing] = useState(null) const columns: Column[] = [ { header: 'Name', accessor: (g) => g.name }, { header: 'Slug', accessor: (g) => g.slug }, { header: 'Region', accessor: (g) => g.region, sortKey: (g) => g.region }, { header: 'Gen', accessor: (g) => g.generation, sortKey: (g) => g.generation }, { header: 'Year', accessor: (g) => g.releaseYear ?? '-', sortKey: (g) => g.releaseYear ?? 0 }, ] return (

Games

setEditing(g)} keyFn={(g) => g.id} /> {showCreate && ( createGame.mutate(data as CreateGameInput, { onSuccess: () => setShowCreate(false), }) } onClose={() => setShowCreate(false)} isSubmitting={createGame.isPending} /> )} {editing && ( updateGame.mutate( { id: editing.id, data: data as UpdateGameInput }, { onSuccess: () => setEditing(null) }, ) } onClose={() => setEditing(null)} isSubmitting={updateGame.isPending} onDelete={() => deleteGame.mutate(editing.id, { onSuccess: () => setEditing(null), }) } isDeleting={deleteGame.isPending} detailUrl={`/admin/games/${editing.id}`} /> )}
) }