import { useState } from 'react' import type { EncounterDetail, UpdateEncounterInput } from '../types' import { useEvolutions } from '../hooks/useEncounters' import { TypeBadge } from './TypeBadge' interface StatusChangeModalProps { encounter: EncounterDetail onUpdate: (data: { id: number data: UpdateEncounterInput }) => void onClose: () => void isPending: boolean region?: string } function formatEvolutionMethod(evo: { trigger: string; minLevel: number | null; item: string | null; heldItem: string | null; condition: string | null }): string { const parts: string[] = [] if (evo.trigger === 'level-up' && evo.minLevel) { parts.push(`Level ${evo.minLevel}`) } else if (evo.trigger === 'level-up') { parts.push('Level up') } else if (evo.trigger === 'use-item' && evo.item) { parts.push(evo.item.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase())) } else if (evo.trigger === 'trade') { parts.push('Trade') } else { parts.push(evo.trigger.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase())) } if (evo.heldItem) { parts.push(`holding ${evo.heldItem.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase())}`) } if (evo.condition) { parts.push(evo.condition) } return parts.join(', ') } 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 [deathLevel, setDeathLevel] = useState('') const [cause, setCause] = useState('') const activePokemonId = currentPokemon?.id ?? pokemon.id const { data: evolutions, isLoading: evolutionsLoading } = useEvolutions( showEvolve ? activePokemonId : null, region, ) 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).