import { useState } from 'react' import type { EncounterDetail, UpdateEncounterInput } from '../types' import { useEvolutions, useForms } from '../hooks/useEncounters' import { TypeBadge } from './TypeBadge' import { formatEvolutionMethod } from '../utils/formatEvolution' interface StatusChangeModalProps { encounter: EncounterDetail onUpdate: (data: { id: number data: UpdateEncounterInput }) => void onClose: () => void isPending: boolean region?: string } export function StatusChangeModal({ encounter, onUpdate, onClose, isPending, region, }: StatusChangeModalProps) { const { pokemon, currentPokemon, route, nickname, catchLevel, faintLevel, deathCause } = encounter const isDead = faintLevel !== null const displayPokemon = currentPokemon ?? pokemon const [showConfirm, setShowConfirm] = useState(false) const [showEvolve, setShowEvolve] = useState(false) const [showFormChange, setShowFormChange] = useState(false) const [deathLevel, setDeathLevel] = useState('') const [cause, setCause] = useState('') const activePokemonId = currentPokemon?.id ?? pokemon.id const { data: evolutions, isLoading: evolutionsLoading } = useEvolutions( showEvolve ? activePokemonId : null, region, ) const { data: forms } = useForms(isDead ? null : activePokemonId) const handleConfirmDeath = () => { onUpdate({ id: encounter.id, data: { faintLevel: deathLevel ? Number(deathLevel) : undefined, deathCause: cause || undefined, }, }) } const handleEvolve = (toPokemonId: number) => { onUpdate({ id: encounter.id, data: { currentPokemonId: toPokemonId }, }) } return (
Loading evolutions...
)} {!evolutionsLoading && evolutions && evolutions.length === 0 && (No evolutions available
)} {!evolutionsLoading && evolutions && evolutions.length > 0 && (This cannot be undone (Nuzlocke rules).