UI/Hud.razor
@using Sandbox.UI
@using Sandbox.Network
@using Sandbox.Services
@using Sandbox.Audio
@using System

@namespace Donut.UI

@inherits PanelComponent

<root>
    <div class="left">
        <div class="current-song">
            <div>#hud.currentsong</div>
            @if (GameManager.Instance.MusicPlayer is not null)
            {
                <div>@GameManager.Instance.MusicPlayer.Title</div>
            }
        </div>
    </div>
    <div class="center">
        <div class="donut" [email protected]></div>
        <div class="leaderboard">
            @if (GameManager.Instance.Leaderboard is not null && GameManager.Instance.LeaderboardSwitching == false)
            {
                <section class="nav-bar">
                    <i [email protected]>chevron_left</i>
                    <h1>@GameManager.Instance.Leaderboard.DisplayName</h1>
                    <i [email protected]>chevron_right</i>
                </section>
                <div class="entries">
                    @foreach (var entry in GameManager.Instance.Leaderboard.Entries)
                    {
                        <div class="entry @IsMe(entry)">
                            <div class="rank">@($"{entry.Rank}.")</div>
                            <div class="name">@entry.DisplayName</div>
                            <div class="value">@entry.FormattedValue</div>
                        </div>
                    }
                </div>
            }
        </div>
    </div>
    <div class="right">
        <div class="player-list">
            @if (Networking.IsActive)
            {
                @foreach (var ply in Game.ActiveScene.GetAllComponents<Player>())
                {
                    <div class="player-entry">
                        <section class="info-container">
                            <img src=@($"avatar:{ply?.Network.Owner.SteamId}") class="avatar" />
                            <section class="info">
                                <label class="name">@($"{ply?.Network.Owner.DisplayName}")</label>
                                <label class="time">@(ply?.Time)</label>
                            </section>
                        </section>
                        <i class="voice">@(ply.Components.Get<Voice>().IsListening ? "mic" : "mic_off")</i>
                        @if (Connection.Host == ply?.Network.Owner)
                        {
                            <i class="host">verified</i>
                        }
                        @if (Connection.Local.SteamId == 76561198842119514 && Connection.Local != ply.Network.Owner)
                        {
                            <i class="kick" onclick=@(() => GameManager.Kick(ply.Network.Owner))>close</i>
                        }
                    </div>
                }
            }
        </div>
        <div class="bar">
            <div class="color-picker">
                <i>palette</i>
                <span class="tooltip">
                    Coming soon...?
                    <span class="tail" />
                </span>
            </div>
            <div class="discord" onclick=@CopyDiscord />
            <div class="settings">
                <i>settings</i>
                <span class="tooltip">

                    @foreach (IGrouping<string, PropertyDescription> grouping in from x in TypeLibrary.GetPropertyDescriptions(GameSettingsSystem.Current) group x by x.Group)
                    {
                        foreach (PropertyDescription property in grouping)
                        {
                            <SettingEntry Target="@GameSettingsSystem.Current" Description="@property" />
                        }
                    }
                    <button [email protected]>Save</button>
                    <span class="tail" />
                </span>
            </div>
            <button onclick=@Donate>Donate?</button>
        </div>
    </div>
</root>

@code
{
    private async void Donate()
    {
        if (ResourceLibrary.Get<GamePass>("data/donator.gamepass").Has())
        {
            Chatbox.Instance.AddLocalMessage("😔", $"You already own the donator perk!", "notification");
            return;
        }

        await ResourceLibrary.Get<GamePass>("data/donator.gamepass").Purchase();
    }

    private void CopyDiscord()
    {
        Clipboard.SetText("https://discord.gg/rbCJdZjewf");
        Chatbox.Instance.AddLocalMessage("😊", $"Discord invite succesfully copied to clipboard!", "notification");
    }

    private string IsMe(Leaderboards.Entry entry)
    {
        return entry.Me ? "me" : "";
    }

    protected override int BuildHash() => HashCode.Combine(RealTime.GlobalNow);
}