using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.net.Structures.Public;
using Luski.Shared.PublicServers.V1.Enums;
using OpenTK.Mathematics;

namespace Luski.GUI.MainScreen.UI.LuskiControls;

public class ProfileView : UserControl
{
    public SocketUser User { get; set; }

    private ProfileView(IRenderObject user, SocketUser u, ServerProfile p, Role r)
    {
        this.User = u;
        base.Size = new(244.ScaleInt(), 44.ScaleInt());
        base.BackgroundColor = new(34, 34, 34, 255);
        user.Location = new(8.ScaleInt(), 6.ScaleInt());
        user.ForceDistanceUpdate(this);
        user.IgnoreHover = true;

        string name = p.DisplayName;
        if (r.ColorType == ColorType.Full)
        {
            name = $"[color=\"{r.Colors[0].ToDatabaseStr()}\"]{name}[/color]";
        }
        else
        {
            name = $"[gradient colors=\"{r.Colors.ToDB()}\"]{name}[/gradient]";
        }
        LuskiLabel uname = new(Globals.DefaultFont)
        {
            Text = name,
            IgnoreHover = true
        };
        uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(),
            (user.Location.Y + (user.Size.Y / 2) - (uname.Size.Y / 2)));
        Controls.Add(uname);
        Controls.Add(user);
    }
    
    public static async Task<ProfileView> Make(SocketUser u, ServerProfile p, Role r)
    {
        ProfileView m = new(await p.MakeRct(u, new(32.ScaleInt())), u, p, r);
        return m;
    }
}