using Microsoft.AspNetCore.Components;
using Portfolio.Domain.Features.Pokemon;

namespace Portfolio.WebUI.Server.Components.Component.Pokemon_Components
{
    partial class PokemonSelector
    {

            [Parameter]
    public List<Pokemon> PokemonList { get; set; } = new();

    [Parameter]
    public Pokemon? SelectedPokemon { get; set; }

    [Parameter]
    public EventCallback<Pokemon> OnPokemonSelected { get; set; }

    private string SearchTerm { get; set; } = string.Empty;

    private List<Pokemon> FilteredPokemon =>
        string.IsNullOrWhiteSpace(SearchTerm)
            ? PokemonList
            : PokemonList.Where(p =>
                p.PokemonName.Contains(SearchTerm, StringComparison.OrdinalIgnoreCase)).ToList();

    private async Task HandleSearch(ChangeEventArgs e)
    {
        SearchTerm = e?.Value?.ToString() ?? "";
    }

    private async Task SelectPokemon(Pokemon pokemon)
    {
        await OnPokemonSelected.InvokeAsync(pokemon);
    }
    }
}

