@model PagedList.IPagedList<PantheonApi.Data.DbModels.Pantheon.tPA_SyncCycle>
@using PagedList.Mvc;
@{
    ViewBag.Title = "Sync status";
    Layout = null;
}

<div id="SyncStatusList">
    <h2>Sync status</h2>
    <h6>Device: @Html.DisplayFor(modelItem => modelItem.FirstOrDefault().anDeviceId) - 
        @Ajax.ActionLink("Refresh", "SyncStatusChild", "SyncManager",
            new { deviceId = ViewBag.DeviceId },
                new AjaxOptions
                {
                    InsertionMode = InsertionMode.Replace,
                    UpdateTargetId = "SyncStatusList",
                    OnBegin = "startLoading('SyncStatusList')"
                })
    </h6>

    <div class="table-responsive">
        <table class="table table-hover table-striped">
            <tr>
                <th>
                    Device ID
                </th>
                <th>
                    Started
                </th>
                <th>
                    Ended
                </th>
                <th>
                    Duration of sync
                </th>
                <th>
                   Status
                </th>
                <th>
                    Data
                </th>
                <th></th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.anDeviceId)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.adStarted)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.adEnded)
                    </td>
                    <td>
                        @if (item.adStarted != null && item.adEnded != null)
                        {
                            <span>@item.adEnded.Value.Subtract(item.adStarted)</span>
                        }
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.acStatus)
                    </td>
                    <td>
                        @if (!string.IsNullOrWhiteSpace(item.acData))
                        {
                            <span title="@item.acData">@item.acData.Substring(0, 15)</span>
                        }
                    </td>
                    <td></td>
                </tr>
            }
        </table>
    </div>
    <br />
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

    <div class="text-center">
        @Html.PagedListPager(Model, page => Url.Action("SyncStatusChild", "SyncManager", new { page, deviceId = ViewBag.DeviceId }),
         PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions()
         {
             HttpMethod = "GET",
             UpdateTargetId = "SyncStatusList"
         }))
    </div>
</div>
