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

namespace Portfolio.WebUI.Server.Components.Pages.Pokemon_Pages
{
    public partial class PokemonEdit
    {
        [Parameter] public int Id { get; set; }
        private Pokemon? pokemon;

        protected override async Task OnInitializedAsync()
        {
            pokemon = await PokemonService.GetPokemonByIdAsync(Id);
        }

        private async Task ReceivePokemon(Pokemon p)
        {
            // Save received pokemon as Pokemon 1
            pokemon = p;

            // Server console (Blazor Server)
            Console.WriteLine($"[Pokemon 1] #{pokemon.PokemonId} {pokemon.PokemonName} | {pokemon.PokemonType} | {pokemon.SleepType} | {pokemon.Speciality} | Var:{pokemon.IsVariation} {pokemon.VariationName}");

            // Browser console
            await JS.InvokeVoidAsync("console.log", "Pokemon 1:", pokemon);
        }

        private async Task HandleSubmit()
        {
            await PokemonService.UpdatePokemonAsync(pokemon);
            //Navigation.NavigateTo("/pokemonsleep");
            await JS.InvokeVoidAsync("history.back");
        }

        private async void Cancel()
        {
            await JS.InvokeVoidAsync("history.back");

        }

        private bool HideLabel { get; set; } = true;
        private void Toggle()
        {
            HideLabel = !HideLabel;
        }

    }
}
