2026-02-07 14:20:26 +01:00
|
|
|
|
import { useState, useEffect, useMemo } from 'react'
|
2026-02-05 15:28:50 +01:00
|
|
|
|
import { useRoutePokemon } from '../hooks/useGames'
|
2026-02-11 21:48:29 +01:00
|
|
|
|
import { useNameSuggestions } from '../hooks/useRuns'
|
2026-02-16 20:39:41 +01:00
|
|
|
|
import { EncounterMethodBadge, getMethodLabel, METHOD_ORDER } from './EncounterMethodBadge'
|
|
|
|
|
|
import type { Route, EncounterDetail, EncounterStatus, RouteEncounterDetail } from '../types'
|
2026-02-05 15:28:50 +01:00
|
|
|
|
|
|
|
|
|
|
interface EncounterModalProps {
|
|
|
|
|
|
route: Route
|
2026-02-08 12:18:12 +01:00
|
|
|
|
gameId: number
|
2026-02-11 21:48:29 +01:00
|
|
|
|
runId: number
|
2026-02-16 20:39:41 +01:00
|
|
|
|
namingScheme?: string | null | undefined
|
|
|
|
|
|
isGenlocke?: boolean | undefined
|
|
|
|
|
|
existing?: EncounterDetail | undefined
|
|
|
|
|
|
dupedPokemonIds?: Set<number> | undefined
|
|
|
|
|
|
retiredPokemonIds?: Set<number> | undefined
|
2026-02-05 15:28:50 +01:00
|
|
|
|
onSubmit: (data: {
|
|
|
|
|
|
routeId: number
|
|
|
|
|
|
pokemonId: number
|
2026-02-16 20:39:41 +01:00
|
|
|
|
nickname?: string | undefined
|
2026-02-05 15:28:50 +01:00
|
|
|
|
status: EncounterStatus
|
2026-02-16 20:39:41 +01:00
|
|
|
|
catchLevel?: number | undefined
|
2026-02-05 15:28:50 +01:00
|
|
|
|
}) => void
|
2026-02-16 20:39:41 +01:00
|
|
|
|
onUpdate?:
|
|
|
|
|
|
| ((data: {
|
|
|
|
|
|
id: number
|
|
|
|
|
|
data: {
|
|
|
|
|
|
nickname?: string | undefined
|
|
|
|
|
|
status?: EncounterStatus | undefined
|
|
|
|
|
|
faintLevel?: number | undefined
|
|
|
|
|
|
deathCause?: string | undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
}) => void)
|
|
|
|
|
|
| undefined
|
2026-02-05 15:28:50 +01:00
|
|
|
|
onClose: () => void
|
|
|
|
|
|
isPending: boolean
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 16:41:24 +01:00
|
|
|
|
const statusOptions: {
|
|
|
|
|
|
value: EncounterStatus
|
|
|
|
|
|
label: string
|
|
|
|
|
|
color: string
|
|
|
|
|
|
}[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'caught',
|
|
|
|
|
|
label: 'Caught',
|
2026-02-20 20:48:16 +01:00
|
|
|
|
color:
|
|
|
|
|
|
'bg-green-900/40 text-green-300 light:bg-green-100 light:text-green-800 border-green-700 light:border-green-300',
|
2026-02-14 16:41:24 +01:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'fainted',
|
|
|
|
|
|
label: 'Fainted',
|
2026-02-20 20:48:16 +01:00
|
|
|
|
color:
|
|
|
|
|
|
'bg-red-900/40 text-red-300 light:bg-red-100 light:text-red-800 border-red-700 light:border-red-300',
|
2026-02-14 16:41:24 +01:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'missed',
|
|
|
|
|
|
label: 'Missed / Ran',
|
2026-02-17 20:48:42 +01:00
|
|
|
|
color: 'bg-surface-2 text-text-primary border-border-default',
|
2026-02-14 16:41:24 +01:00
|
|
|
|
},
|
|
|
|
|
|
]
|
2026-02-05 15:28:50 +01:00
|
|
|
|
|
2026-02-07 14:20:26 +01:00
|
|
|
|
const SPECIAL_METHODS = ['starter', 'gift', 'fossil', 'trade']
|
2026-02-07 13:50:49 +01:00
|
|
|
|
|
2026-02-17 19:38:29 +01:00
|
|
|
|
interface GroupedEncounter {
|
|
|
|
|
|
encounter: RouteEncounterDetail
|
|
|
|
|
|
conditions: string[]
|
|
|
|
|
|
displayRate: number | null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getUniqueConditions(pokemon: RouteEncounterDetail[]): string[] {
|
|
|
|
|
|
const conditions = new Set<string>()
|
|
|
|
|
|
for (const rp of pokemon) {
|
|
|
|
|
|
if (rp.condition) conditions.add(rp.condition)
|
|
|
|
|
|
}
|
|
|
|
|
|
return [...conditions].sort()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 16:41:24 +01:00
|
|
|
|
function groupByMethod(
|
2026-02-17 19:38:29 +01:00
|
|
|
|
pokemon: RouteEncounterDetail[],
|
|
|
|
|
|
selectedCondition: string | null
|
|
|
|
|
|
): { method: string; pokemon: GroupedEncounter[] }[] {
|
|
|
|
|
|
const groups = new Map<string, Map<number, GroupedEncounter>>()
|
|
|
|
|
|
|
|
|
|
|
|
// Build a lookup: pokemonId+method -> condition -> rate
|
|
|
|
|
|
const rateByCondition = new Map<string, Map<string, number>>()
|
2026-02-07 14:20:26 +01:00
|
|
|
|
for (const rp of pokemon) {
|
2026-02-17 19:38:29 +01:00
|
|
|
|
if (rp.condition) {
|
|
|
|
|
|
const key = `${rp.pokemonId}:${rp.encounterMethod}`
|
|
|
|
|
|
let condMap = rateByCondition.get(key)
|
|
|
|
|
|
if (!condMap) {
|
|
|
|
|
|
condMap = new Map()
|
|
|
|
|
|
rateByCondition.set(key, condMap)
|
|
|
|
|
|
}
|
|
|
|
|
|
condMap.set(rp.condition, rp.encounterRate)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const rp of pokemon) {
|
|
|
|
|
|
// When a specific condition is selected, skip pokemon with 0% under that condition
|
|
|
|
|
|
if (selectedCondition) {
|
|
|
|
|
|
const key = `${rp.pokemonId}:${rp.encounterMethod}`
|
|
|
|
|
|
const condMap = rateByCondition.get(key)
|
|
|
|
|
|
if (condMap) {
|
|
|
|
|
|
const rate = condMap.get(selectedCondition)
|
|
|
|
|
|
if (rate === 0) continue
|
|
|
|
|
|
// Skip entries for other conditions (we only want one entry per pokemon)
|
|
|
|
|
|
if (rp.condition && rp.condition !== selectedCondition) continue
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// "All" mode: skip 0% entries
|
|
|
|
|
|
if (rp.encounterRate === 0 && rp.condition) continue
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let methodGroup = groups.get(rp.encounterMethod)
|
|
|
|
|
|
if (!methodGroup) {
|
|
|
|
|
|
methodGroup = new Map()
|
|
|
|
|
|
groups.set(rp.encounterMethod, methodGroup)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const existing = methodGroup.get(rp.pokemonId)
|
|
|
|
|
|
if (existing) {
|
|
|
|
|
|
if (rp.condition) existing.conditions.push(rp.condition)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Determine the display rate
|
|
|
|
|
|
let displayRate: number | null = null
|
|
|
|
|
|
const isSpecial = SPECIAL_METHODS.includes(rp.encounterMethod)
|
|
|
|
|
|
if (!isSpecial) {
|
|
|
|
|
|
if (selectedCondition) {
|
|
|
|
|
|
const key = `${rp.pokemonId}:${rp.encounterMethod}`
|
|
|
|
|
|
const condMap = rateByCondition.get(key)
|
|
|
|
|
|
if (condMap) {
|
|
|
|
|
|
displayRate = condMap.get(selectedCondition) ?? null
|
|
|
|
|
|
} else {
|
|
|
|
|
|
displayRate = rp.encounterRate
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (!rp.condition) {
|
|
|
|
|
|
// "All" mode: show the base rate for non-condition entries
|
|
|
|
|
|
displayRate = rp.encounterRate
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
methodGroup.set(rp.pokemonId, {
|
|
|
|
|
|
encounter: rp,
|
|
|
|
|
|
conditions: rp.condition ? [rp.condition] : [],
|
|
|
|
|
|
displayRate,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-02-07 14:20:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
return [...groups.entries()]
|
|
|
|
|
|
.sort(([a], [b]) => {
|
|
|
|
|
|
const ai = METHOD_ORDER.indexOf(a)
|
|
|
|
|
|
const bi = METHOD_ORDER.indexOf(b)
|
|
|
|
|
|
return (ai === -1 ? 999 : ai) - (bi === -1 ? 999 : bi)
|
|
|
|
|
|
})
|
2026-02-17 19:38:29 +01:00
|
|
|
|
.map(([method, pokemonMap]) => ({
|
|
|
|
|
|
method,
|
|
|
|
|
|
pokemon: [...pokemonMap.values()].sort((a, b) => (b.displayRate ?? 0) - (a.displayRate ?? 0)),
|
|
|
|
|
|
}))
|
2026-02-07 13:50:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-08 13:14:43 +01:00
|
|
|
|
function pickRandomPokemon(
|
|
|
|
|
|
pokemon: RouteEncounterDetail[],
|
2026-02-14 16:41:24 +01:00
|
|
|
|
dupedIds?: Set<number>
|
2026-02-08 13:14:43 +01:00
|
|
|
|
): RouteEncounterDetail | null {
|
2026-02-17 19:38:29 +01:00
|
|
|
|
// Deduplicate by pokemonId (conditions may create multiple entries)
|
|
|
|
|
|
const seen = new Set<number>()
|
|
|
|
|
|
const unique = pokemon.filter((rp) => {
|
|
|
|
|
|
if (rp.encounterRate === 0) return false
|
|
|
|
|
|
if (seen.has(rp.pokemonId)) return false
|
|
|
|
|
|
seen.add(rp.pokemonId)
|
|
|
|
|
|
return true
|
|
|
|
|
|
})
|
|
|
|
|
|
const eligible = dupedIds ? unique.filter((rp) => !dupedIds.has(rp.pokemonId)) : unique
|
2026-02-08 13:14:43 +01:00
|
|
|
|
if (eligible.length === 0) return null
|
2026-02-16 20:39:41 +01:00
|
|
|
|
return eligible[Math.floor(Math.random() * eligible.length)] ?? null
|
2026-02-08 13:14:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-05 15:28:50 +01:00
|
|
|
|
export function EncounterModal({
|
|
|
|
|
|
route,
|
2026-02-08 12:18:12 +01:00
|
|
|
|
gameId,
|
2026-02-11 21:48:29 +01:00
|
|
|
|
runId,
|
|
|
|
|
|
namingScheme,
|
2026-02-14 10:00:36 +01:00
|
|
|
|
isGenlocke,
|
2026-02-05 15:28:50 +01:00
|
|
|
|
existing,
|
2026-02-07 21:08:25 +01:00
|
|
|
|
dupedPokemonIds,
|
2026-02-09 10:05:03 +01:00
|
|
|
|
retiredPokemonIds,
|
2026-02-05 15:28:50 +01:00
|
|
|
|
onSubmit,
|
|
|
|
|
|
onUpdate,
|
|
|
|
|
|
onClose,
|
|
|
|
|
|
isPending,
|
|
|
|
|
|
}: EncounterModalProps) {
|
2026-02-16 20:39:41 +01:00
|
|
|
|
const { data: routePokemon, isLoading: loadingPokemon } = useRoutePokemon(route.id, gameId)
|
2026-02-05 15:28:50 +01:00
|
|
|
|
|
2026-02-16 20:39:41 +01:00
|
|
|
|
const [selectedPokemon, setSelectedPokemon] = useState<RouteEncounterDetail | null>(null)
|
|
|
|
|
|
const [status, setStatus] = useState<EncounterStatus>(existing?.status ?? 'caught')
|
2026-02-05 15:28:50 +01:00
|
|
|
|
const [nickname, setNickname] = useState(existing?.nickname ?? '')
|
2026-02-16 20:39:41 +01:00
|
|
|
|
const [catchLevel, setCatchLevel] = useState<string>(existing?.catchLevel?.toString() ?? '')
|
2026-02-05 15:28:50 +01:00
|
|
|
|
const [faintLevel, setFaintLevel] = useState<string>('')
|
2026-02-05 18:36:08 +01:00
|
|
|
|
const [deathCause, setDeathCause] = useState('')
|
2026-02-05 15:28:50 +01:00
|
|
|
|
const [search, setSearch] = useState('')
|
2026-02-17 19:38:29 +01:00
|
|
|
|
const [selectedCondition, setSelectedCondition] = useState<string | null>(null)
|
2026-02-05 15:28:50 +01:00
|
|
|
|
|
|
|
|
|
|
const isEditing = !!existing
|
|
|
|
|
|
|
2026-02-11 21:48:29 +01:00
|
|
|
|
const showSuggestions = !!namingScheme && status === 'caught' && !isEditing
|
2026-02-16 20:39:41 +01:00
|
|
|
|
const lineagePokemonId = isGenlocke && selectedPokemon ? selectedPokemon.pokemonId : null
|
2026-02-14 16:41:24 +01:00
|
|
|
|
const {
|
|
|
|
|
|
data: suggestions,
|
|
|
|
|
|
refetch: regenerate,
|
|
|
|
|
|
isFetching: loadingSuggestions,
|
|
|
|
|
|
} = useNameSuggestions(showSuggestions ? runId : null, lineagePokemonId)
|
2026-02-11 21:48:29 +01:00
|
|
|
|
|
2026-02-05 15:28:50 +01:00
|
|
|
|
// Pre-select pokemon when editing
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (existing && routePokemon) {
|
2026-02-16 20:39:41 +01:00
|
|
|
|
const match = routePokemon.find((rp) => rp.pokemonId === existing.pokemonId)
|
2026-02-05 15:28:50 +01:00
|
|
|
|
if (match) setSelectedPokemon(match)
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [existing, routePokemon])
|
|
|
|
|
|
|
2026-02-17 19:38:29 +01:00
|
|
|
|
const availableConditions = useMemo(
|
|
|
|
|
|
() => (routePokemon ? getUniqueConditions(routePokemon) : []),
|
|
|
|
|
|
[routePokemon]
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-02-05 15:28:50 +01:00
|
|
|
|
const filteredPokemon = routePokemon?.filter((rp) =>
|
2026-02-14 16:41:24 +01:00
|
|
|
|
rp.pokemon.name.toLowerCase().includes(search.toLowerCase())
|
2026-02-05 15:28:50 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2026-02-07 14:20:26 +01:00
|
|
|
|
const groupedPokemon = useMemo(
|
2026-02-17 19:38:29 +01:00
|
|
|
|
() => (filteredPokemon ? groupByMethod(filteredPokemon, selectedCondition) : []),
|
|
|
|
|
|
[filteredPokemon, selectedCondition]
|
2026-02-07 14:20:26 +01:00
|
|
|
|
)
|
|
|
|
|
|
const hasMultipleGroups = groupedPokemon.length > 1
|
|
|
|
|
|
|
2026-02-05 15:28:50 +01:00
|
|
|
|
const handleSubmit = () => {
|
|
|
|
|
|
if (isEditing && onUpdate) {
|
|
|
|
|
|
onUpdate({
|
|
|
|
|
|
id: existing.id,
|
|
|
|
|
|
data: {
|
|
|
|
|
|
nickname: nickname || undefined,
|
|
|
|
|
|
status,
|
|
|
|
|
|
faintLevel: faintLevel ? Number(faintLevel) : undefined,
|
2026-02-05 18:36:08 +01:00
|
|
|
|
deathCause: deathCause || undefined,
|
2026-02-05 15:28:50 +01:00
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (selectedPokemon) {
|
|
|
|
|
|
onSubmit({
|
|
|
|
|
|
routeId: route.id,
|
|
|
|
|
|
pokemonId: selectedPokemon.pokemonId,
|
|
|
|
|
|
nickname: nickname || undefined,
|
|
|
|
|
|
status,
|
|
|
|
|
|
catchLevel: catchLevel ? Number(catchLevel) : undefined,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const canSubmit = isEditing || selectedPokemon
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
|
|
|
|
|
<div className="fixed inset-0 bg-black/50" onClick={onClose} />
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="relative bg-surface-1 rounded-xl shadow-xl max-w-lg w-full max-h-[90vh] overflow-y-auto">
|
|
|
|
|
|
<div className="sticky top-0 bg-surface-1 border-b border-border-default px-6 py-4 rounded-t-xl">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
<div className="flex items-center justify-between">
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<h2 className="text-lg font-semibold text-text-primary">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
{isEditing ? 'Edit Encounter' : 'Log Encounter'}
|
|
|
|
|
|
</h2>
|
2026-02-17 21:08:53 +01:00
|
|
|
|
<button onClick={onClose} className="text-text-tertiary hover:text-text-primary">
|
2026-02-16 20:39:41 +01:00
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
<path
|
|
|
|
|
|
strokeLinecap="round"
|
|
|
|
|
|
strokeLinejoin="round"
|
|
|
|
|
|
strokeWidth={2}
|
|
|
|
|
|
d="M6 18L18 6M6 6l12 12"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<p className="text-sm text-text-tertiary mt-1">{route.name}</p>
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="px-6 py-4 space-y-4">
|
|
|
|
|
|
{/* Pokemon Selection (only for new encounters) */}
|
|
|
|
|
|
{!isEditing && (
|
|
|
|
|
|
<div>
|
2026-02-08 13:14:43 +01:00
|
|
|
|
<div className="flex items-center justify-between mb-1">
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<label className="block text-sm font-medium text-text-secondary">Pokemon</label>
|
2026-02-08 13:14:43 +01:00
|
|
|
|
{!loadingPokemon && routePokemon && routePokemon.length > 0 && (
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
disabled={
|
|
|
|
|
|
loadingPokemon ||
|
|
|
|
|
|
!routePokemon ||
|
|
|
|
|
|
(dupedPokemonIds
|
2026-02-16 20:39:41 +01:00
|
|
|
|
? routePokemon.every((rp) => dupedPokemonIds.has(rp.pokemonId))
|
2026-02-08 13:14:43 +01:00
|
|
|
|
: false)
|
|
|
|
|
|
}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
if (routePokemon) {
|
2026-02-16 20:39:41 +01:00
|
|
|
|
setSelectedPokemon(pickRandomPokemon(routePokemon, dupedPokemonIds))
|
2026-02-08 13:14:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
}}
|
2026-02-20 20:48:16 +01:00
|
|
|
|
className="px-2.5 py-1 text-xs font-medium rounded-lg border border-purple-600 text-purple-400 light:text-purple-700 light:border-purple-500 hover:bg-purple-900/20 light:hover:bg-purple-50 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
|
2026-02-08 13:14:43 +01:00
|
|
|
|
>
|
|
|
|
|
|
{selectedPokemon ? 'Re-roll' : 'Randomize'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2026-02-05 15:28:50 +01:00
|
|
|
|
{loadingPokemon ? (
|
|
|
|
|
|
<div className="flex items-center justify-center py-4">
|
2026-02-17 21:08:53 +01:00
|
|
|
|
<div className="w-10 h-10 border-2 border-accent-400 border-t-transparent rounded-full animate-spin" />
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
) : filteredPokemon && filteredPokemon.length > 0 ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{(routePokemon?.length ?? 0) > 6 && (
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder="Search pokemon..."
|
|
|
|
|
|
value={search}
|
|
|
|
|
|
onChange={(e) => setSearch(e.target.value)}
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="w-full px-3 py-1.5 mb-2 rounded-lg border border-border-default bg-surface-2 text-text-primary text-sm focus:outline-none focus:ring-2 focus:ring-accent-400"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2026-02-17 19:38:29 +01:00
|
|
|
|
{availableConditions.length > 0 && (
|
|
|
|
|
|
<div className="flex flex-wrap gap-1 mb-2">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setSelectedCondition(null)}
|
|
|
|
|
|
className={`px-2.5 py-1 text-xs font-medium rounded-full border transition-colors ${
|
|
|
|
|
|
selectedCondition === null
|
2026-02-17 21:08:53 +01:00
|
|
|
|
? 'bg-purple-900/40 border-purple-600 text-purple-300'
|
|
|
|
|
|
: 'border-border-default text-text-tertiary hover:border-purple-600'
|
2026-02-17 19:38:29 +01:00
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
All
|
|
|
|
|
|
</button>
|
|
|
|
|
|
{availableConditions.map((cond) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={cond}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setSelectedCondition(cond)}
|
|
|
|
|
|
className={`px-2.5 py-1 text-xs font-medium rounded-full border transition-colors capitalize ${
|
|
|
|
|
|
selectedCondition === cond
|
2026-02-17 21:08:53 +01:00
|
|
|
|
? 'bg-purple-900/40 border-purple-600 text-purple-300'
|
|
|
|
|
|
: 'border-border-default text-text-tertiary hover:border-purple-600'
|
2026-02-17 19:38:29 +01:00
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{cond}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-02-07 14:20:26 +01:00
|
|
|
|
<div className="max-h-64 overflow-y-auto space-y-3">
|
|
|
|
|
|
{groupedPokemon.map(({ method, pokemon }, groupIdx) => (
|
|
|
|
|
|
<div key={method}>
|
2026-02-17 20:48:42 +01:00
|
|
|
|
{groupIdx > 0 && <div className="border-t border-border-default mb-3" />}
|
2026-02-07 14:20:26 +01:00
|
|
|
|
{hasMultipleGroups && (
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="text-xs font-medium text-text-tertiary mb-1.5">
|
2026-02-07 14:20:26 +01:00
|
|
|
|
{getMethodLabel(method)}
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-02-07 14:20:26 +01:00
|
|
|
|
<div className="grid grid-cols-3 gap-2">
|
2026-02-17 19:38:29 +01:00
|
|
|
|
{pokemon.map(({ encounter: rp, conditions, displayRate }) => {
|
2026-02-16 20:39:41 +01:00
|
|
|
|
const isDuped = dupedPokemonIds?.has(rp.pokemonId) ?? false
|
2026-02-17 19:38:29 +01:00
|
|
|
|
const isSelected =
|
|
|
|
|
|
selectedPokemon?.pokemonId === rp.pokemonId &&
|
|
|
|
|
|
selectedPokemon?.encounterMethod === rp.encounterMethod
|
2026-02-07 21:08:25 +01:00
|
|
|
|
return (
|
|
|
|
|
|
<button
|
2026-02-17 19:38:29 +01:00
|
|
|
|
key={`${rp.encounterMethod}-${rp.pokemonId}`}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
type="button"
|
2026-02-16 20:39:41 +01:00
|
|
|
|
onClick={() => !isDuped && setSelectedPokemon(rp)}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
disabled={isDuped}
|
|
|
|
|
|
className={`flex flex-col items-center p-2 rounded-lg border text-center transition-colors ${
|
|
|
|
|
|
isDuped
|
2026-02-17 20:48:42 +01:00
|
|
|
|
? 'opacity-40 cursor-not-allowed border-border-default'
|
2026-02-17 19:38:29 +01:00
|
|
|
|
: isSelected
|
2026-02-17 21:08:53 +01:00
|
|
|
|
? 'border-accent-400 bg-accent-900/30'
|
2026-02-17 20:48:42 +01:00
|
|
|
|
: 'border-border-default hover:border-border-default'
|
2026-02-07 21:08:25 +01:00
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{rp.pokemon.spriteUrl ? (
|
|
|
|
|
|
<img
|
|
|
|
|
|
src={rp.pokemon.spriteUrl}
|
|
|
|
|
|
alt={rp.pokemon.name}
|
|
|
|
|
|
className="w-10 h-10"
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="w-10 h-10 rounded-full bg-surface-3 flex items-center justify-center text-xs font-bold">
|
2026-02-16 20:39:41 +01:00
|
|
|
|
{rp.pokemon.name[0]?.toUpperCase()}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<span className="text-xs text-text-secondary mt-1 capitalize">
|
2026-02-07 21:08:25 +01:00
|
|
|
|
{rp.pokemon.name}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
{isDuped && (
|
2026-02-17 21:08:53 +01:00
|
|
|
|
<span className="text-[10px] text-text-tertiary italic">
|
2026-02-14 16:41:24 +01:00
|
|
|
|
{retiredPokemonIds?.has(rp.pokemonId)
|
|
|
|
|
|
? 'retired (HoF)'
|
|
|
|
|
|
: 'already caught'}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
2026-02-16 20:39:41 +01:00
|
|
|
|
{!isDuped && SPECIAL_METHODS.includes(rp.encounterMethod) && (
|
|
|
|
|
|
<EncounterMethodBadge method={rp.encounterMethod} />
|
|
|
|
|
|
)}
|
2026-02-17 19:38:29 +01:00
|
|
|
|
{!isDuped && displayRate !== null && displayRate !== undefined && (
|
2026-02-20 20:48:16 +01:00
|
|
|
|
<span className="text-[10px] text-purple-400 light:text-purple-700 font-medium">
|
2026-02-17 19:38:29 +01:00
|
|
|
|
{displayRate}%
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{!isDuped &&
|
|
|
|
|
|
selectedCondition === null &&
|
|
|
|
|
|
conditions.length > 0 && (
|
2026-02-20 20:48:16 +01:00
|
|
|
|
<span className="text-[10px] text-purple-400 light:text-purple-700">
|
2026-02-17 19:38:29 +01:00
|
|
|
|
{conditions.join(', ')}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
{!isDuped && (
|
2026-02-17 21:08:53 +01:00
|
|
|
|
<span className="text-[10px] text-text-tertiary">
|
2026-02-07 21:08:25 +01:00
|
|
|
|
Lv. {rp.minLevel}
|
2026-02-16 20:39:41 +01:00
|
|
|
|
{rp.maxLevel !== rp.minLevel && `–${rp.maxLevel}`}
|
2026-02-07 21:08:25 +01:00
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)
|
|
|
|
|
|
})}
|
2026-02-07 14:20:26 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-05 15:28:50 +01:00
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<p className="text-sm text-text-tertiary py-2">No pokemon data for this route</p>
|
2026-02-05 15:28:50 +01:00
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Editing: show pokemon info */}
|
|
|
|
|
|
{isEditing && existing && (
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="flex items-center gap-3 p-3 bg-surface-0/50 rounded-lg">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
{existing.pokemon.spriteUrl ? (
|
|
|
|
|
|
<img
|
|
|
|
|
|
src={existing.pokemon.spriteUrl}
|
|
|
|
|
|
alt={existing.pokemon.name}
|
|
|
|
|
|
className="w-12 h-12"
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="w-12 h-12 rounded-full bg-surface-3 flex items-center justify-center text-lg font-bold">
|
2026-02-16 20:39:41 +01:00
|
|
|
|
{existing.pokemon.name[0]?.toUpperCase()}
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
<div>
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="font-medium text-text-primary capitalize">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
{existing.pokemon.name}
|
|
|
|
|
|
</div>
|
2026-02-17 21:08:53 +01:00
|
|
|
|
<div className="text-xs text-text-tertiary">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
Caught at Lv. {existing.catchLevel ?? '?'}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Status */}
|
|
|
|
|
|
<div>
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<label className="block text-sm font-medium text-text-secondary mb-1">Status</label>
|
2026-02-05 15:28:50 +01:00
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
{statusOptions.map((opt) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={opt.value}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setStatus(opt.value)}
|
|
|
|
|
|
className={`flex-1 px-3 py-2 rounded-lg border text-sm font-medium transition-colors ${
|
|
|
|
|
|
status === opt.value
|
|
|
|
|
|
? opt.color
|
2026-02-17 21:08:53 +01:00
|
|
|
|
: 'border-border-default text-text-tertiary hover:border-border-accent'
|
2026-02-05 15:28:50 +01:00
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{opt.label}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Nickname (for caught) */}
|
|
|
|
|
|
{status === 'caught' && (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label
|
|
|
|
|
|
htmlFor="nickname"
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="block text-sm font-medium text-text-secondary mb-1"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
>
|
|
|
|
|
|
Nickname
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
id="nickname"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={nickname}
|
|
|
|
|
|
onChange={(e) => setNickname(e.target.value)}
|
|
|
|
|
|
placeholder="Give it a name..."
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="w-full px-3 py-2 rounded-lg border border-border-default bg-surface-2 text-text-primary focus:outline-none focus:ring-2 focus:ring-accent-400"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
/>
|
2026-02-11 21:48:29 +01:00
|
|
|
|
{showSuggestions && suggestions && suggestions.length > 0 && (
|
|
|
|
|
|
<div className="mt-2">
|
|
|
|
|
|
<div className="flex items-center justify-between mb-1.5">
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<span className="text-xs text-text-tertiary">Suggestions ({namingScheme})</span>
|
2026-02-11 21:48:29 +01:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => regenerate()}
|
|
|
|
|
|
disabled={loadingSuggestions}
|
2026-02-17 21:08:53 +01:00
|
|
|
|
className="text-xs text-text-link hover:text-accent-300 disabled:opacity-50 transition-colors"
|
2026-02-11 21:48:29 +01:00
|
|
|
|
>
|
|
|
|
|
|
{loadingSuggestions ? 'Loading...' : 'Regenerate'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex flex-wrap gap-1.5">
|
|
|
|
|
|
{suggestions.map((name) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={name}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setNickname(name)}
|
|
|
|
|
|
className={`px-2.5 py-1 text-xs rounded-full border transition-colors ${
|
|
|
|
|
|
nickname === name
|
2026-02-20 20:48:16 +01:00
|
|
|
|
? 'bg-accent-900/40 border-accent-600 text-accent-300 light:bg-accent-100 light:text-accent-700'
|
2026-02-17 21:08:53 +01:00
|
|
|
|
: 'border-border-default text-text-secondary hover:border-accent-600 hover:bg-accent-900/20'
|
2026-02-11 21:48:29 +01:00
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{name}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Level (for new caught encounters) */}
|
|
|
|
|
|
{!isEditing && status === 'caught' && (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label
|
|
|
|
|
|
htmlFor="catch-level"
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="block text-sm font-medium text-text-secondary mb-1"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
>
|
|
|
|
|
|
Catch Level
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
id="catch-level"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
min={1}
|
|
|
|
|
|
max={100}
|
|
|
|
|
|
value={catchLevel}
|
|
|
|
|
|
onChange={(e) => setCatchLevel(e.target.value)}
|
|
|
|
|
|
placeholder={
|
|
|
|
|
|
selectedPokemon
|
|
|
|
|
|
? `${selectedPokemon.minLevel}–${selectedPokemon.maxLevel}`
|
|
|
|
|
|
: 'Level'
|
|
|
|
|
|
}
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="w-24 px-3 py-2 rounded-lg border border-border-default bg-surface-2 text-text-primary focus:outline-none focus:ring-2 focus:ring-accent-400"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-02-05 18:36:08 +01:00
|
|
|
|
{/* Faint Level + Death Cause (only when editing a caught pokemon to mark dead) */}
|
2026-02-16 20:39:41 +01:00
|
|
|
|
{isEditing && existing?.status === 'caught' && existing?.faintLevel === null && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label
|
|
|
|
|
|
htmlFor="faint-level"
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="block text-sm font-medium text-text-secondary mb-1"
|
2026-02-16 20:39:41 +01:00
|
|
|
|
>
|
2026-02-17 21:08:53 +01:00
|
|
|
|
Faint Level <span className="font-normal text-text-tertiary">(mark as dead)</span>
|
2026-02-16 20:39:41 +01:00
|
|
|
|
</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
id="faint-level"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
min={1}
|
|
|
|
|
|
max={100}
|
|
|
|
|
|
value={faintLevel}
|
|
|
|
|
|
onChange={(e) => setFaintLevel(e.target.value)}
|
|
|
|
|
|
placeholder="Leave empty if still alive"
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="w-full px-3 py-2 rounded-lg border border-border-default bg-surface-2 text-text-primary focus:outline-none focus:ring-2 focus:ring-accent-400"
|
2026-02-16 20:39:41 +01:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label
|
|
|
|
|
|
htmlFor="death-cause"
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="block text-sm font-medium text-text-secondary mb-1"
|
2026-02-16 20:39:41 +01:00
|
|
|
|
>
|
2026-02-17 21:08:53 +01:00
|
|
|
|
Cause of Death <span className="font-normal text-text-tertiary">(optional)</span>
|
2026-02-16 20:39:41 +01:00
|
|
|
|
</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
id="death-cause"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
maxLength={100}
|
|
|
|
|
|
value={deathCause}
|
|
|
|
|
|
onChange={(e) => setDeathCause(e.target.value)}
|
|
|
|
|
|
placeholder="e.g. Crit from rival's Charizard"
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="w-full px-3 py-2 rounded-lg border border-border-default bg-surface-2 text-text-primary focus:outline-none focus:ring-2 focus:ring-accent-400"
|
2026-02-16 20:39:41 +01:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-17 20:48:42 +01:00
|
|
|
|
<div className="sticky bottom-0 bg-surface-1 border-t border-border-default px-6 py-4 rounded-b-xl flex justify-end gap-3">
|
2026-02-05 15:28:50 +01:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={onClose}
|
2026-02-17 20:48:42 +01:00
|
|
|
|
className="px-4 py-2 text-text-secondary bg-surface-2 rounded-lg font-medium hover:bg-surface-3 transition-colors"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
disabled={!canSubmit || isPending}
|
|
|
|
|
|
onClick={handleSubmit}
|
2026-02-17 21:08:53 +01:00
|
|
|
|
className="px-4 py-2 bg-accent-600 text-white rounded-lg font-medium hover:bg-accent-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
2026-02-05 15:28:50 +01:00
|
|
|
|
>
|
2026-02-14 16:41:24 +01:00
|
|
|
|
{isPending ? 'Saving...' : isEditing ? 'Update' : 'Log Encounter'}
|
2026-02-05 15:28:50 +01:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|