using CommunityToolkit.Maui.Views;
using QwirkleClassLibrary.Games;
using System.Collections.ObjectModel;

namespace Qwirkle;

public partial class PopUpEndGame : Popup
{
	public PopUpEndGame()
	{
		InitializeComponent();

        var scoreboard = game.ObservableScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
        ScoreboardList = new ObservableCollection<KeyValuePair<string, int>>(scoreboard);
    }

    private Game game = ((App)Application.Current!).Game;

    private ObservableCollection<KeyValuePair<string, int>>? scoreboardList;
    public ObservableCollection<KeyValuePair<string, int>>? ScoreboardList
    {
        get => scoreboardList;
        set
        {
            if (scoreboardList != value)
            {
                scoreboardList = value;
                OnPropertyChanged(nameof(ScoreboardList));
            }
        }
    }

    public async void OnButtonNextClick(object sender, EventArgs e)
    {
        await CloseAsync();
    }

}
