@using SharedLibraryCore.Interfaces;

@model IEnumerable<IClientMeta>
@{
    Layout = null;

    var lastHeaderEventDate = DateTime.UtcNow;

    TimeSpan timeSpanForEvent(DateTime When)
    {
        var timePassed = (DateTime.UtcNow - When);
        var daysPassed = timePassed.TotalDays;
        var minutesPassed = timePassed.TotalMinutes;

        if (minutesPassed <= 60)
        {
            return TimeSpan.FromMinutes(5);
        }

        if (minutesPassed > 60 && daysPassed <= 1)
        {
            return TimeSpan.FromHours(1);
        }

        if (daysPassed > 1 && daysPassed <= 7)
        {
            return TimeSpan.FromDays(1);
        }

        if (daysPassed > 7 && daysPassed <= 31)
        {
            return TimeSpan.FromDays(31);
        }

        if (daysPassed > 31 && daysPassed <= 365)
        {
            return TimeSpan.FromDays(31);
        }

        else
        {
            return TimeSpan.FromDays(365);
        }
    }
}

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

@foreach (var meta in Model.OrderByDescending(_meta => _meta.When))
{
    @if ((lastHeaderEventDate - meta.When) > timeSpanForEvent(lastHeaderEventDate))
    {
        <div class="p2 text-white profile-event-timestep">
            <span class="text-primary">&mdash;</span>
            <span>@meta.When.HumanizeForCurrentCulture()</span>
        </div>
        lastHeaderEventDate = meta.When;
    }

    <div class="profile-meta-entry loader-data-time" data-time="@meta.When.ToFileTimeUtc()" title="@Utilities.FormatExt(ViewBag.Localization["WEBFRONT_PROFILE_META_DATE_OCCURRED"], meta.When.ToString())">
        <partial name="~/Views/Client/Profile/Meta/_@(meta.GetType().Name).cshtml" model="meta" />
    </div>
}
