using MauiAppStock.Models;
using MauiAppStock.Data;

namespace MauiAppStock.Views
{
    public partial class EditAssociationPage : ContentPage
    {
        private AppareilPiece _association;

        public EditAssociationPage(AppareilPiece association)
        {
            InitializeComponent();
            _association = association;
            BindingContext = _association;
        }

        private async void OnSaveClicked(object sender, EventArgs e)
        {
            await Database.UpdateAppareilPieceAsync(_association);
            await Navigation.PopAsync();
        }

        private async void OnDeleteClicked(object sender, EventArgs e)
        {
            bool confirm = await DisplayAlert("Confirmation", "Voulez-vous supprimer cette association ?", "Oui", "Non");
            if (confirm)
            {
                await Database.DeleteAppareilPieceAsync(_association);
                await Navigation.PopAsync();
            }
        }
    }
}