@using System.Globalization
@using EzeScanWebApps.MVC.Models.RIA
@using Humanizer
@using NodaTime
@using NodaTime.Text
@model EzeScanWebApps.MVC.Models.RIA.IndexingOverviewModel

@helper GetQueueTypeIcon(OverviewQueueModel item)
{
    switch (item.Type)
    {
        case "personal":
            <span title="Personal queue for @item.Name">
                <font-awesome-icon icon="user"></font-awesome-icon>
            </span>
            break;
        default:
            <font-awesome-icon icon="folder-open"></font-awesome-icon>
            break;
    }
}

@{ ViewBag.Title = Model.Page.Name; }
@{ ViewBag.SubTitle = "Overview"; }
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }

<div class="card">
    <div class="card-header">There are currently @Model.Queues.Count() queues with @Model.Queues.Sum(q => q.Stats.Items) items pending.</div>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>Queue</th>
                <th>Items</th>
                <th>Oldest</th>
            </tr>
            </thead>
            <tbody>
                @foreach (var queue in Model.Queues)
                {
                    <tr>
                        <td>
                            @GetQueueTypeIcon(queue)
                            &nbsp;
                            <a href="@Url.Action("List", new { pageId = Model.Page.Id, queueId = queue.Id })">
                                @queue.Name
                            </a>
                        </td>
                        <td>@queue.Stats.Items</td>
                        <td>
                            @if (queue.Stats.Oldest.HasValue)
                            {
                                <span title="@queue.Stats.Oldest.Value.InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).ToString("G", CultureInfo.CurrentUICulture)">@queue.Stats.Oldest.Value.ToDateTimeOffset().Humanize()</span>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>