using GraphicsManager.Enums;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.GUI.MainScreen.UI.PublicServers.ServerSettingPages;
using Luski.GUI.MainScreen.UI.SettingsPanel;
using OpenTK.Mathematics;

namespace Luski.GUI.MainScreen.UI.PublicServers;

public class ServerSettingCategory : UserControl
{
    private Label Top;
    private static FontInteraction? fi;
    private Rectangle line;
    public string Name
    {
        get => Top.Text;
    }

    private ServerSettings ss;

    public ServerSettingCategory(string Name, ServerSettings SS)
    {
        ss = SS;
        if (fi is null)
        {
            fi = Globals.DefaultFont.Clone();
            fi.FontSize = FontSize.Bold;
        }
        Top = new(fi)
        {
            Location = new(5.ScaleInt(), 5.ScaleInt(), 0),
            Text = Name
        };
        base.BackgroundColor = new(255, 255, 255, 0);
        base.Size = new(307.ScaleInt(), 20.ScaleInt() + Top.Size.Y);
        Top.Location = new((base.Size.X - Top.Size.X) / 2, Top.Location.Y, 0);
        line = new()
        {
            Size = new(base.Size.X, 1.ScaleInt()),
            BackgroundColor = Color4.Gray,
            Location = new(0, base.Size.Y - 1.ScaleInt(), 0)
        };
        line.ForceDistanceUpdate(this);
        Controls.Add(line);
        Controls.Add(Top);
    }
    
    public ServerSettingPageTab AddPage<TPage>(TPage Page) where TPage : IPageBase
    {
        Page.Location = new(ss.fl.Size.X + 40.ScaleInt(), 0, 0);
        Page.Size = new(Globals.ms.CS.X - ss.fl.Size.X - 80.ScaleInt(), Globals.ms.CS.Y);
        Page.AllowHoverFromBehind = true;
        Page.Anchor = ObjectAnchor.All;
        if (Page is PageBaseFlow pbf) pbf.HScrollPixels = Globals.Settings.PerScrollPixels;
        ServerSettingPageTab cb = new(Page.PageName, ss)
        {
            Page = Page
        };
        Controls.Add(cb);
        int f = 5.ScaleInt();
        cb.Location = new (line.Location.X + f, line.Location.Y - f, 0);
        line.Location = new(line.Location.X, line.Location.Y + cb.Size.Y + f, 0);
        Size = new(Size.X, Size.Y + cb.Size.Y + f);
        return cb;
    }
}