using GraphicsManager.Enums;
using GraphicsManager.Objects;
using OpenTK.Mathematics;

namespace Luski.GUI.MainScreen.UI.PublicServers.ServerSettings;

public class SaveWarning : UserControl
{
    public event Func<Task>? SaveClicked; 
    
    public SaveWarning()
    {
        Label warning = new(Globals.DefaultFont)
        {
            Text = "Careful — you have unsaved changes!",
            IgnoreHover = true
        };
        Label savetext = new(Globals.DefaultFont)
        {
            Text = "Save Changes",
            IgnoreHover = true
        };
        Controls.Add(warning);
        base.Size = new(700.ScaleInt(), 52.ScaleInt());
        int space = 10.ScaleInt();
        UserControl uc = new()
        {
            BackgroundColor = new(36, 128, 70, 255),
            Size = new(140.ScaleInt(), 32.ScaleInt()),
            Anchor = ObjectAnchor.Right | ObjectAnchor.Top | ObjectAnchor.Bottom
        };
        savetext.Location = new((uc.Size.X - savetext.Size.X) / 2, ((uc.Size.Y - savetext.Size.Y) / 2));
        uc.MouseEnter += _ =>
        {
            uc.BackgroundColor = new(26, 99, 52, 255);
            return Task.CompletedTask;
        };
        uc.MouseLeave += _ =>
        {
            uc.BackgroundColor = new(36, 128, 70, 255);
            return Task.CompletedTask;
        };
        uc.Clicked += _ =>
        {
            if (SaveClicked is not null) return SaveClicked.Invoke();
            return Task.CompletedTask;
        };
        uc.Location = new(base.Size.X - space - uc.Size.X, space);
        warning.Location = new(space, savetext.Location.Y + uc.Location.Y);
        uc.Controls.Add(savetext);
        uc.ForceDistanceUpdate(this);
        Controls.Add(uc);
        Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top;
        base.BackgroundColor = new(17, 18, 20, 255);
    }
}