namespace Trek_12.Views;
using Stub;
using System.Diagnostics;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;

public partial class PageProfils : ContentPage
{
    public Stub MyStub { get; set; } = new Stub();

    public PageProfils()
	{
		InitializeComponent();
		BindingContext = MyStub;
	}


    async void Button_ClickedAdd(System.Object sender, System.EventArgs e)
    {
        string result = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok");
        Debug.WriteLine("Answer: " + result);
        if (result != null)
        {
            Debug.WriteLine("bam, added");
            MyStub.Add(result, "profile.jpg");
        }
    }


    async void Button_ClickedPop(System.Object sender, System.EventArgs e)
    {
        string result = await DisplayPromptAsync("Info", $"Choose a name to delete : ", "Ok");
        Debug.WriteLine("Answer: " + result);
        if (result != null)
        {
            Debug.WriteLine("bam, deleted");
            MyStub.Pop(result, "profile.jpg");
        }
        else Debug.WriteLine("Pseudo not found");
    }

    async void Button_ClickedModify(System.Object sender, System.EventArgs e)
    {
        string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok");
        Debug.WriteLine("Answer: " + result);
        if (result != null)
        {
            string tomodify = await DisplayPromptAsync("Info", $"How will you rename it ?: ", "Ok");
            Debug.WriteLine("Answer: " + tomodify);
            if (tomodify != null)
            {
                Debug.WriteLine("bam, modified");
                bool ismodified = MyStub.Modify(result, tomodify);

                if (ismodified)
                {
                    Debug.WriteLine("Modified");
                }
                else Debug.WriteLine("Player not found");
            }
        }
        else Debug.WriteLine("Did not found");
    }

}

