using GameAtlas.Models;

namespace GameAtlas.Views;

public partial class PageProfil : ContentPage
{
    public Manager ProfilManager => (App.Current as App).MyManager;
	public PageProfil()
	{
		InitializeComponent();
        BindingContext = ProfilManager;
        SwitchPage();
    }

    async void SwitchPage()
    {
        if (ProfilManager.ConnectedUser == null)
        {
            await Navigation.PushAsync(new PageConnexion());
        }
        else
        {
            await Shell.Current.GoToAsync("//page/PageProfil");
        }
    }

    async void OnGame_Tapped(System.Object sender, EventArgs e)
    {
        var selectedjeu = (sender as ImageButton)?.BindingContext as Jeu;
        if (selectedjeu != null)
        {
            
            await Navigation.PushAsync(new PageJeu(selectedjeu));
        }
       
    }

    async void OnAdmin_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e)
    {
        await Shell.Current.GoToAsync(nameof(PageAdmin));
    }

    async void OnDisconnect_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e)
    {
        await Shell.Current.GoToAsync("//page/PageAccueil");
        ProfilManager.ConnectedUser = null;
    }
}