@model Disco.Web.Models.User.ShowModel
@{
    Authorization.Require(Claims.User.ShowAssignmentHistory);
}
<div id="UserDetailTab-AssignmentHistory" class="UserPart">
    @if (Model.User.DeviceUserAssignments.Count > 0)
    { 
        <table class="genericData">
            <tr>
                <th>Device Serial #
                </th>
                <th>Device Asset #
                </th>
                <th>Device Model
                </th>
                <th>Device Profile
                </th>
                <th>Device Batch
                </th>
                <th>Assigned
                </th>
                <th>Unassigned
                </th>
            </tr>
            @foreach (var dua in Model.User.DeviceUserAssignments.OrderByDescending(m => m.AssignedDate))
            {
                <tr>
                    <td>
                        @if (Authorization.Has(Claims.Device.Show))
                        {
                            @Html.ActionLink(dua.Device.SerialNumber, MVC.Device.Show(dua.DeviceSerialNumber))
                        }
                        else
                        {
                            @dua.Device.SerialNumber
                        }
                    </td>
                    <td>
                        @if (!string.IsNullOrWhiteSpace(dua.Device.AssetNumber))
                        {
                            @dua.Device.AssetNumber
                        }
                        else
                        {
                            <span class="smallMessage">N/A</span>
                        }
                    </td>
                    <td>
                        @if (dua.Device.DeviceModelId.HasValue)
                        {
                            if (Authorization.Has(Claims.Config.DeviceModel.Show))
                            {
                            @Html.ActionLink(dua.Device.DeviceModel.ToString(), MVC.Config.DeviceModel.Index(dua.Device.DeviceModelId))
                            }
                            else
                            {
                            @dua.Device.DeviceModel.ToString()
                            }
                        }
                        else
                        {
                            <span class="smallMessage">Unknown</span>
                        }
                    </td>
                    <td>
                        @if (Authorization.Has(Claims.Config.DeviceProfile.Show))
                        {
                            @Html.ActionLink(dua.Device.DeviceProfile.ToString(), MVC.Config.DeviceProfile.Index(dua.Device.DeviceProfileId))
                        }
                        else
                        {
                            @dua.Device.DeviceProfile.ToString()
                        }
                    </td>
                    <td>
                        @if (dua.Device.DeviceBatchId.HasValue)
                        {
                            if (Authorization.Has(Claims.Config.DeviceBatch.Show))
                            {
                            @Html.ActionLink(dua.Device.DeviceBatch.ToString(), MVC.Config.DeviceBatch.Index(dua.Device.DeviceBatchId))
                            }
                            else
                            {
                            @dua.Device.DeviceModel.ToString()
                            }
                        }
                        else
                        {
                            <span class="smallMessage">None</span>
                        }
                    </td>
                    <td>
                        @CommonHelpers.FriendlyDate(dua.AssignedDate)
                    </td>
                    <td>
                        @CommonHelpers.FriendlyDate(dua.UnassignedDate, "Current")
                    </td>
                </tr>
            }
        </table>
    }
    else
    { 
        <span class="smallMessage">No Assignment History Available</span>
    }
    <script>
        $('#UserDetailTabItems').append('<li><a href="#UserDetailTab-AssignmentHistory">Assignment History [@(Model.User.DeviceUserAssignments.Count)]</a></li>');
    </script>
</div>
