using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using Luski.net.Structures.Public;
using OpenTK.Mathematics;

namespace Luski.GUI.MainScreen.UI.LuskiControls;

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

    private UserView(IRenderObject user, SocketUser u, ServerProfile p, Role r, bool offline)
    {
        this.User = u;
        base.Size = new(244.ScaleInt(), 44.ScaleInt());
        base.BackgroundColor = new(34, 34, 34, 255);
        user.Location = new(8.ScaleInt(), 6.ScaleInt(), 0);
        user.ForceDistanceUpdate(this);
        Label uname = new(Globals.DefaultFont)
        {
            Text = p.DisplayName,
            Color = r.Color.ToColor4()
        };
        if (offline) uname.Color = new(uname.Color.R, uname.Color.G, uname.Color.B, uname.Color.A * 0.6f);
        uname.Location = new(user.Location.X + user.Size.X + 8.ScaleInt(),
            (user.Location.Y + (user.Size.Y / 2) - (uname.Size.Y / 2)), 0);
        Controls.Add(uname);
        Controls.Add(user);
    }
    
    public static async Task<UserView> Make(SocketUser u, ServerProfile p, Role r, bool offline)
    {
        UserView m = new(await p.MakeRct(u, new(32.ScaleInt())), u, p, r, offline);
        return m;
    }
}