using MauiAppStock.ViewModels;
using MauiAppStock.Models;

namespace MauiAppStock.Views
{
    public partial class PiecesPage : ContentPage
    {
        public PiecesPage()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            var vm = BindingContext as PiecesViewModel;
            vm.LoadPiecesCommand.Execute(null);
        }

        private async void OnAddPieceClicked(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new AddPiecePage());
        }

        private async void OnPieceTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item is Piece piece)
            {
                await Navigation.PushAsync(new EditPiecePage(piece));
            }
        }
    }
}