import { useState } from 'react' import { useParams, useNavigate, Link } from 'react-router-dom' import { useGenlocke } from '../../hooks/useGenlockes' import { useGames } from '../../hooks/useGames' import { useUpdateGenlocke, useDeleteGenlocke, useAddGenlockeLeg, useDeleteGenlockeLeg, } from '../../hooks/useAdmin' import { DeleteConfirmModal } from '../../components/admin/DeleteConfirmModal' export function AdminGenlockeDetail() { const { genlockeId } = useParams<{ genlockeId: string }>() const id = Number(genlockeId) const navigate = useNavigate() const { data: genlocke, isLoading } = useGenlocke(id) const { data: games = [] } = useGames() const updateGenlocke = useUpdateGenlocke() const deleteGenlocke = useDeleteGenlocke() const addLeg = useAddGenlockeLeg(id) const deleteLeg = useDeleteGenlockeLeg(id) const [name, setName] = useState(null) const [status, setStatus] = useState(null) const [showDelete, setShowDelete] = useState(false) const [addingLeg, setAddingLeg] = useState(false) const [selectedGameId, setSelectedGameId] = useState('') if (isLoading) return
Loading...
if (!genlocke) return
Genlocke not found
const editName = name ?? genlocke.name const editStatus = status ?? genlocke.status const hasChanges = editName !== genlocke.name || editStatus !== genlocke.status const handleSave = () => { const data: Record = {} if (editName !== genlocke.name) data['name'] = editName if (editStatus !== genlocke.status) data['status'] = editStatus if (Object.keys(data).length === 0) return updateGenlocke.mutate( { id, data }, { onSuccess: () => { setName(null) setStatus(null) }, } ) } const handleAddLeg = () => { if (!selectedGameId) return addLeg.mutate( { gameId: Number(selectedGameId) }, { onSuccess: () => { setAddingLeg(false) setSelectedGameId('') }, } ) } return (
{/* Header */}
setName(e.target.value)} className="w-full px-3 py-2 border rounded-md bg-surface-2 border-border-default" />

Created {new Date(genlocke.createdAt).toLocaleDateString()}

{/* Rules (read-only) */}

Rules

Genlocke rules:
              {JSON.stringify(genlocke.genlockeRules, null, 2)}
            
Nuzlocke rules:
              {JSON.stringify(genlocke.nuzlockeRules, null, 2)}
            
{/* Legs */}

Legs ({genlocke.legs.length})

{addingLeg && (
)} {genlocke.legs.length === 0 ? (
No legs yet. Add one to get started.
) : (
{genlocke.legs.map((leg) => ( ))}
Order Game Run Status Enc. Deaths Actions
{leg.legOrder} {leg.game.name} {leg.runId ? ( Run #{leg.runId} ) : ( )} {leg.runStatus ? ( {leg.runStatus} ) : ( )} {leg.encounterCount} {leg.deathCount}
)}
{/* Stats */}

Stats

Legs

{genlocke.stats.legsCompleted} / {genlocke.stats.totalLegs}

Encounters

{genlocke.stats.totalEncounters}

Deaths

{genlocke.stats.totalDeaths}

Survival Rate

{genlocke.stats.totalEncounters > 0 ? `${Math.round(((genlocke.stats.totalEncounters - genlocke.stats.totalDeaths) / genlocke.stats.totalEncounters) * 100)}%` : '\u2014'}

{showDelete && ( deleteGenlocke.mutate(id, { onSuccess: () => navigate('/admin/genlockes'), }) } onCancel={() => setShowDelete(false)} isDeleting={deleteGenlocke.isPending} /> )}
) }