@model IEnumerable<SharedLibraryCore.Dtos.ProfileMeta>
@{
    Layout = null;

    var timeSinceLastEvent = DateTime.MinValue;

    dynamic formatPenaltyInfo(SharedLibraryCore.Dtos.ProfileMeta meta)
    {
        var penalty = meta.Value as SharedLibraryCore.Dtos.PenaltyInfo;

        string localizationKey = meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ?
            $"WEBFRONT_CLIENT_META_PENALIZED_{penalty.PenaltyTypeText.ToUpper()}" :
            $"WEBFRONT_CLIENT_META_WAS_PENALIZED_{penalty.PenaltyTypeText.ToUpper()}";

        string localizationMessage = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex[localizationKey];
        var regexMatch = System.Text.RegularExpressions.Regex.Match(localizationMessage, @"^.*{{([^{}]+)}}.+$");
        string penaltyType = regexMatch.Groups[1].Value.ToString();
        var secondMatch = System.Text.RegularExpressions.Regex.Match(localizationMessage, @"\{\{.+\}\}(.+)\{0\}(.+)\{1\}");

        return new
        {
            Type = meta.Type,
            Match = secondMatch,
            Penalty = penalty,
            PenaltyType = penaltyType
        };
    }
}

@if (Model.Count() == 0)
{
    <div class="p2 text-muted profile-event-timestep">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_NONE"]</div>
}

@foreach (var meta in Model.OrderByDescending(_meta => _meta.When))
{
    @if (Math.Abs((meta.When - timeSinceLastEvent).TotalDays) >= 1)
    {
        <div class="p2 text-white profile-event-timestep">
            <span class="text-primary">&mdash;</span>
            <span>@SharedLibraryCore.Utilities.GetTimePassed(meta.When, true)</span>
        </div>

        timeSinceLastEvent = meta.When;
    }

    @switch (meta.Type)
    {
        case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ChatMessage:
        case SharedLibraryCore.Dtos.ProfileMeta.MetaType.QuickMessage:
            <div class="profile-meta-entry loader-data-time" data-time="@meta.When">
                <span style="color:white;">></span>
                <span class="client-message text-muted @(meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.QuickMessage ? "font-italic" : "")" data-serverid="@meta.Extra" data-when="@meta.When.ToFileTimeUtc()" title="@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_MESSAGE_CONTEXT"]"> <color-code value="@meta.Value" allow="@ViewBag.EnableColorCodes"></color-code></span>
            </div>
            break;
        case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ReceivedPenalty:
        case SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized:
            <div class="profile-meta-entry loader-data-time" data-time="@meta.When">
                @{ var penaltyInfo = formatPenaltyInfo(meta); }
                @if (meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized)
                {
                    <span class="penalties-color-@penaltyInfo.Penalty.PenaltyTypeText.ToLower()">@penaltyInfo.PenaltyType</span>
                    <span>@penaltyInfo.Match.Groups[1].ToString()</span> <!-- by -->

                    <span class="text-highlight">
                        <!-- punisher -->
                        <a class="link-inverse" href="@penaltyInfo.Penalty.OffenderId">
                            <color-code value="@penaltyInfo.Penalty.OffenderName" allow="@ViewBag.EnableColorCodes"></color-code>
                        </a>
                    </span>
                    <span>@penaltyInfo.Match.Groups[2].ToString()</span> <!-- for -->
                    <span class="@(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white"
                          data-penalty-id="@penaltyInfo.Penalty.Id"><color-code value="@penaltyInfo.Penalty.Offense" allow="@ViewBag.EnableColorCodes"></color-code> @(ViewBag.Authorized ? penaltyInfo.Penalty.AdditionalPenaltyInformation : "")</span>
                    }

                @if (meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.ReceivedPenalty)
                {
                    <span class="penalties-color-@penaltyInfo.Penalty.PenaltyTypeText.ToLower()">@penaltyInfo.PenaltyType</span> <!-- actioned -->
                    <span>@penaltyInfo.Match.Groups[1].ToString()</span> <!-- by -->
                    <span class="text-highlight">
                        <a class="link-inverse" href="@penaltyInfo.Penalty.PunisherId">
                            <color-code value="@penaltyInfo.Penalty.PunisherName" allow="@ViewBag.EnableColorCodes"></color-code>
                        </a> <!-- punisher -->
                    </span>
                    <span>@penaltyInfo.Match.Groups[2]</span>
                    <span class="@(ViewBag.Authorized ? "automated-penalty-info-detailed" : "") text-white"
                          data-penalty-id="@penaltyInfo.Penalty.Id">
                        <color-code value="@penaltyInfo.Penalty.Offense" allow="@ViewBag.EnableColorCodes"></color-code> @(ViewBag.Authorized ? penaltyInfo.Penalty.AdditionalPenaltyInformation : "")
                    </span>
                }
            </div>
            break;
    }
}