@model SharedLibraryCore.Dtos.ServerInfo

@{
    Layout = null;
    int half = Model.ClientCount == 0 || Model.Players.Count == 0 ? 0 : (int)Math.Ceiling(Model.ClientCount / 2.0);
}
<div class="col-12 col-md-8 d-none d-md-block">
    @{
        for (int i = 0; i < Model.ChatHistory.Count; i++)
        {
            if (Model.ChatHistory[i] == null ||
                Model.ChatHistory[i].Message == null ||
                Model.ChatHistory[i].Name == null)
            {
                continue;
            }

            if (Model.ChatHistory[i].Message == "CONNECTED")
            {
                <span class="text-light">
                    <span class="oi oi-account-login mr-2 text-success"> </span>
                    <color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                </span><br />
            }
            if (Model.ChatHistory[i].Message == "DISCONNECTED")
            {
                <span class="text-light">
                    <span class="oi oi-account-logout mr-2 text-danger"> </span>
                    <color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                </span><br />
            }
            if (Model.ChatHistory[i].Message != "CONNECTED" && Model.ChatHistory[i].Message != "DISCONNECTED")
            {
                <span class="text-light">
                    <color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                </span>
                <span>
                    &mdash;
                    <color-code value="@Model.ChatHistory[i].Message.Substring(0, Math.Min(40, Model.ChatHistory[i].Message.Length))" allow="@ViewBag.EnableColorCodes"></color-code>
                </span><br />
            }
        }
    }
</div>
<div class="col-md-4">
    <div class="row">
        <div class="col-6 text-left text-md-right">
            @{
                for (int i = 0; i < half; i++)
                {
                    if (i > Model.Players.Count - 1)
                    {
                        continue;
                    }
                    string levelColorClass = !ViewBag.Authorized ? "" : $"level-color-{Model.Players[i].LevelInt}";
                    <a asp-controller="Client" asp-action="ProfileAsync" asp-route-id="@Model.Players[i].ClientId" class="@levelColorClass">
                        <color-code value="@Model.Players[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                    </a>
                    <br />
                }
            }
        </div>
        <div class="col-6 text-right">
            @{
                for (int i = half; i < Math.Min(Model.ClientCount, Model.Players.Count); i++)
                {
                    if (i > Model.Players.Count - 1)
                    {
                        continue;
                    }
                    string levelColorClass = !ViewBag.Authorized ? "" : $"level-color-{Model.Players[i].LevelInt}";
                    <a asp-controller="Client" asp-action="ProfileAsync" asp-route-id="@Model.Players[i].ClientId" class="@levelColorClass">
                        <color-code value="@Model.Players[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                    </a>
                    <br />
                }
            }
        </div>
    </div>
</div>
@if (Model.ChatHistory.Count > 0)
{
    <div class="w-100 border-bottom d-md-none d-block mt-1 mb-1"></div>
}
<div class="col-12 col-md-8 d-md-none d-block text-left">
    @{
        for (int i = 0; i < Model.ChatHistory.Count; i++)
        {
            if (Model.ChatHistory[i] == null ||
                Model.ChatHistory[i].Message == null ||
                Model.ChatHistory[i].Name == null)
            {
                continue;
            }

            if (Model.ChatHistory[i].Message == "CONNECTED")
            {
                <span class="text-light">
                    <span class="oi oi-account-login mr-2 text-success"> </span>
                    <color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                </span><br />
            }
            if (Model.ChatHistory[i].Message == "DISCONNECTED")
            {
                <span class="text-light">
                    <span class="oi oi-account-logout mr-2 text-danger"> </span>
                    <color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                </span><br />
            }
            if (Model.ChatHistory[i].Message != "CONNECTED" && Model.ChatHistory[i].Message != "DISCONNECTED")
            {
                <span class="text-light">
                    <color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
                </span>
                <span> &mdash; 
                    <color-code value="@Model.ChatHistory[i].Message.Substring(0, Math.Min(40, Model.ChatHistory[i].Message.Length))" allow="@ViewBag.EnableColorCodes"></color-code> 
                </span><br />
            }
        }
    }
</div>