import { useState, useEffect } from 'react'; import { Search, Trash2, ImageOff } from 'lucide-react'; import { pokemonApi } from '../services/pokemonApi'; interface PokemonCardProps { pokemonString: string; index: number; onUpdate: (index: number, value: string) => void; onRemove: (index: number) => void; onOpenSelector: (index: number) => void; isCompact?: boolean; } export function PokemonCard({ pokemonString, index, onUpdate, onRemove, onOpenSelector, isCompact = false }: PokemonCardProps) { const [pokemonInfo, setPokemonInfo] = useState<{ name: string; imageUrl: string | null; displayName: string; } | null>(null); const [loading, setLoading] = useState(false); const [imageError, setImageError] = useState(false); useEffect(() => { const loadPokemonInfo = async () => { if (!pokemonString.trim()) { setPokemonInfo(null); return; } setLoading(true); setImageError(false); try { const info = await pokemonApi.getPokemonInfo(pokemonString); setPokemonInfo(info); } catch (error) { console.error('Failed to load Pokemon info:', error); setPokemonInfo(null); } finally { setLoading(false); } }; loadPokemonInfo(); }, [pokemonString]); const handleImageError = () => { setImageError(true); }; if (isCompact) { return (
{/* Image du Pokémon */}
{loading ? (
) : pokemonInfo?.imageUrl && !imageError ? ( {pokemonInfo.displayName} ) : ( )}
{/* Informations et contrôles */}
onUpdate(index, e.target.value)} className="w-full text-sm border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500" placeholder="pikachu level=50 moves=thunderbolt,quick-attack" /> {pokemonInfo && (

{pokemonInfo.displayName}

)}
{/* Boutons d'action */}
); } return (
{/* Image du Pokémon */}
{loading ? (
) : pokemonInfo?.imageUrl && !imageError ? ( {pokemonInfo.displayName} ) : ( )}
{/* Nom du Pokémon */} {pokemonInfo && (

{pokemonInfo.displayName}

#{index + 1}

)} {/* Champ de saisie */}