@model IEnumerable<Disco.Models.Services.Jobs.Noticeboards.IHeldDeviceItem>
@{
    ViewBag.Title = Html.ToBreadcrumb("Public Reports", MVC.Public.Public.Index(), "Held Devices", null);
    Html.BundleDeferred("~/Style/Public/HeldDevices");
}
<div class="clearfix page">
    <div class="column1">
        @{
            var DevicesInProcess = Model.Where(i => !i.ReadyForReturn && !i.WaitingForUserAction).ToArray();
        }
        <h2>In Process (@DevicesInProcess.Length)</h2>
        <table class="dataTable">
            @foreach (var item in DevicesInProcess.OrderBy(i => i.DeviceComputerNameFriendly))
            {
                <tr>
                    <td class="id">
                        @item.DeviceComputerNameFriendly
                    </td>
                    <td class="description">
                        @if (item.UserId != null)
                        {
                            <span class="user">@item.UserDisplayName (@item.UserIdFriendly)</span>
                        }
                        @if (!string.IsNullOrWhiteSpace(item.DeviceLocation))
                        {
                            if (item.UserId != null)
                            {
                            <text> - </text>
                            }
                            @item.DeviceLocation
                        }
                        else
                        {
                            if (item.UserId == null)
                            {
                            @item.DeviceSerialNumber
                            }
                        }
                        @if (item.EstimatedReturnTime.HasValue)
                        { 
                            <span class="smallMessage">(Expected: @CommonHelpers.FriendlyDate(item.EstimatedReturnTime))</span>
                        }
                    </td>
                </tr>
            }
        </table>
    </div>
    <div class="column2">
        @{
            var WaitingForUserActionJobs = Model.Where(i => i.WaitingForUserAction).ToArray();
        }
        <h2>Waiting for User Action (@WaitingForUserActionJobs.Length)</h2>
        <table class="dataTable">
            @foreach (var item in WaitingForUserActionJobs.OrderBy(i => i.DeviceComputerNameFriendly))
            {
                <tr>
                    <td class="id">
                        @item.DeviceComputerNameFriendly
                    </td>
                    <td class="description">
                        @if (item.UserId != null)
                        {
                            <span class="user">@item.UserDisplayName (@item.UserIdFriendly)</span>
                        }
                        @if (!string.IsNullOrWhiteSpace(item.DeviceLocation))
                        {
                            if (item.UserId != null)
                            {
                            <text> - </text>
                            }
                            @item.DeviceLocation
                        }
                        else
                        {
                            if (item.UserId == null)
                            {
                            @item.DeviceSerialNumber
                            }
                        }
                    </td>
                    <td class="timestamp@(item.IsAlert ? " Alert" : string.Empty)">Since @CommonHelpers.FriendlyDate(item.WaitingForUserActionSince)
                    </td>
                </tr>
            }
        </table>
        <hr />
        @{
            var DevicesReadyForReturn = Model.Where(i => i.ReadyForReturn && !i.WaitingForUserAction).ToArray();
        }
        <h2>Ready for Return (@DevicesReadyForReturn.Length)</h2>
        <table class="dataTable">
            @foreach (var item in DevicesReadyForReturn.OrderBy(i => i.DeviceComputerNameFriendly))
            {
                <tr>
                    <td class="id">
                        @item.DeviceComputerNameFriendly
                    </td>
                    <td class="description">
                        @if (item.UserId != null)
                        {
                            <span class="user">@item.UserDisplayName (@item.UserIdFriendly)</span>
                        }
                        @if (!string.IsNullOrWhiteSpace(item.DeviceLocation))
                        {
                            if (item.UserId != null)
                            {
                            <text> - </text>
                            }
                            @item.DeviceLocation
                        }
                        else
                        {
                            if (item.UserId == null)
                            {
                            @item.DeviceSerialNumber
                            }
                        }
                    </td>
                    <td class="timestamp@(item.IsAlert ? " Alert" : string.Empty)">Ready @CommonHelpers.FriendlyDate(item.ReadyForReturnSince)
                    </td>
                </tr>
            }
        </table>
    </div>
</div>
