using Qwirkle.Views;
using QwirkleClassLibrary;
using QwirkleClassLibrary.Games;
using Microsoft.Maui.Controls;
using Qwirkle.Pages;
using QwirkleClassLibrary.Persistences;

namespace Qwirkle
{
    public partial class MainPage : ContentPage
    {

        public MainPage()
        {
            InitializeComponent();
            BindingContext = this;
        }

        public void OnInfoClicked(object sender, EventArgs e)
        {
            DisplayAlert("Game notification", "Enter minimun 2 player and max 4 player !", "Ok ! Lets's go !");

            Shell.Current.GoToAsync("SetPlayers");
            //Navigation.PushAsync(new SetPlayers());
        }
        
        public async void OnContinueClicked(object sender, EventArgs e)
        {
            IGamePersistence gameLoad = new GamePersistenceXml();
            try
            {
                ((App)Application.Current!).Game = gameLoad.LoadGame();
                await Shell.Current.GoToAsync("Gameboard");
                //await Navigation.PushAsync(new Gameboard());
            }
            catch
            {
                await DisplayAlert("Error", "No game found", "Got it !");
                await Navigation.PopAsync();
            }

            if (!((App)Application.Current!).Game.GameRunning)
            {
                await DisplayAlert("Error", "No game found", "Got it !");
                await Navigation.PopAsync();
            }
        }
        
        public void OnRulesClicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new Rules());
        }

        public void OnSettingsClicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new Settings());
        }

        public void OnCreditsClicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new Credits());
        }

        public void OnCLeaderboardClicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new Leaderboard());
        }

    }

}
