using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Portfolio.Domain.Features.Pokemon;
using System.Text.Json;

namespace Portfolio.WebUI.Server.Components.Component.Pokemon_Components
{
    partial class PokemonDownloadButton
    {
        [Parameter]
        public List<Pokemon> _Pokemon { get; set; }

        private List<Pokemon> pokemons = new List<Pokemon>();


        protected override void OnParametersSet()
        {
            if (_Pokemon != null)
            {
                pokemons = _Pokemon.ToList();

            }
        }

        private async Task DownloadPokemonJson()
        {
            var json = JsonSerializer.Serialize(pokemons, new JsonSerializerOptions { WriteIndented = true });
            await JS.InvokeVoidAsync("downloadFileFromText", "pokemon.json", "application/json", json);
        }
    }
}
