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

namespace Qwirkle
{
    public partial class App
    {
        public App()
        {
            string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string targetPath = Path.Combine(appDataPath, "Programs", "Files");
            Directory.CreateDirectory(targetPath);
            Directory.SetCurrentDirectory(targetPath);
            
            InitializeComponent();

            //MainPage = new NavigationPage(new MainPage());
            MainPage = new AppShell();

            Routing.RegisterRoute(nameof(SetPlayers), typeof(SetPlayers));
            Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard));
            Routing.RegisterRoute(nameof(Rules), typeof(Rules));
            Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
            Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard));

            ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson();

            try
            {
                Ld = leaderboardLoad.LoadLeaderboard();
            }
            catch
            {
                Ld = new Leaderboard();
            }
        }

        
        public Game Game { get; set; } = new();
        public Leaderboard Ld { get; set; }
    }
}
