@using IW4MAdmin.Plugins.Stats
@using System.Text.Json
@model List<IW4MAdmin.Plugins.Stats.Web.Dtos.TopStatsInfo>
@{
    Layout = null;
    var loc = Utilities.CurrentLocalization.LocalizationIndex.Set;
}

@if (Model.Count == 0)
{
    <div class="card m-0 mt-15">
        <div class="d-flex">
            <i class="oi oi-timer align-self-center mb-10" style="font-size: 6rem;"></i>
            <div class="p-15">
                <h2 class="content-title mb-0">@Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_NOQUALIFY"]</h2>
                <span class="text-muted">@ViewBag.Localization["WEBFRONT_TOP_PLAYERS_NOQUALIFY_SUBTITLE"]</span>
            </div>
        </div>
    </div>
}

@foreach (var stat in Model)
{
    <div class="card m-0 mt-15 p-20 d-flex flex-column flex-md-row justify-content-between">
        <div class="d-flex flex-column  w-full w-md-quarter">
            <div class="d-flex align-items-center mb-15">
                <div class="d-flex text-muted">
                    <span class="font-size-20">#</span>
                    <div style="font-size: 4.5rem; line-height: 4.5rem;font-family: SFMono-Regular,Menlo,Monaco,Consolas,'Liberation Mono','Courier New',monospace;">@stat.Ranking</div>
                </div>
                <div class="ml-10">
                    <div class="d-flex flex-row">
                        <a asp-controller="Client" asp-action="Profile" asp-route-id="@stat.ClientId" class="no-decoration text-light-dm text-dark-lm font-size-20 text-force-break" style="line-height: 2.5rem;">
                            <color-code value="@stat.Name" allow="@ViewBag.EnableColorCodes"></color-code>
                        </a>
                        @if (stat.RatingChange > 0)
                        {
                            <div class="d-flex flex-column text-center ml-5 mr-5 align-self-center">
                                <div class="oi oi-caret-top text-success client-rating-change-up"></div>
                                <div class="client-rating-change-amount text-success">@stat.RatingChange</div>
                            </div>
                        }
                        @if (stat.RatingChange < 0)
                        {
                            <div class="d-flex flex-column text-center ml-5 mr-5 align-self-center">
                                <div class="client-rating-change-amount client-rating-change-amount-down text-danger">@Math.Abs(stat.RatingChange)</div>
                                <div class="oi oi-caret-bottom text-danger client-rating-change-down"></div>
                            </div>
                        }
                    </div>

                    <div class="font-size-14">
                        <span class="text-primary">
                            @stat.Performance.ToNumericalString()
                        </span>
                        @if (stat.ServerId == null)
                        {
                            <span class="text-muted">@loc["WEBFRONT_ADV_STATS_RATING"].FormatExt("").ToLower()</span>
                        }

                        else
                        {
                            <span class="text-muted">@loc["WEBFRONT_ADV_STATS_PERFORMANCE"].FormatExt("").ToLower()</span>
                        }
                    </div>
                </div>
            </div>

            <div class="d-flex flex-column font-size-12 text-right text-md-left">
                <div>
                    <span class="text-primary">@stat.Kills.ToNumericalString()</span><span class="text-muted"> @loc["PLUGINS_STATS_TEXT_KILLS"]</span>
                </div>
                <div>
                    <span class="text-primary">@stat.Deaths.ToNumericalString()</span><span class="text-muted"> @loc["PLUGINS_STATS_TEXT_DEATHS"]</span><br/>
                </div>
                <div>
                    <span class="text-primary">@stat.KDR</span><span class="text-muted"> @loc["PLUGINS_STATS_TEXT_KDR"]</span>
                </div>
                <div>
                    <span class="text-primary">@stat.TimePlayedValue.HumanizeForCurrentCulture() </span><span class="text-muted">@loc["WEBFRONT_PROFILE_PLAYER"]</span>
                </div>
                <div>
                    <span class="text-primary"> @stat.LastSeenValue.HumanizeForCurrentCulture() </span><span class="text-muted">@loc["WEBFRONT_PROFILE_LSEEN"]</span>
                </div>
            </div>
        </div>
        <div class="w-full w-md-half client-rating-graph pt-10 pb-10">
            <canvas id="rating_history_@(stat.ClientId + "_" + stat.Id)" data-history="@(JsonSerializer.Serialize(stat.PerformanceHistory.OrderBy(perf => perf.OccurredAt)))"></canvas>
        </div>
        <div class="w-quarter align-self-center d-flex justify-content-center">
            <img class="w-100 h-100" src="~/images/stats/ranks/rank_@(stat.ZScore.RankIconIndexForZScore()).png" alt="@stat.Performance"/>
        </div>
    </div>
}
