@using MileageTraker.Web.Models
@model IEnumerable<User>

@{
    ViewBag.Title = "Users";
    var grid = new WebGrid(Model, rowsPerPage: 45);
}
    
@Html.Partial("_StatusMessage")

<h2 id="user-title">@ViewBag.Title</h2>

<div class="btn-toolbar pull-right">
    @using (Html.BeginForm("DetailsFullName", "User", FormMethod.Get, new {@class = "navbar-search form-inline" }))
    {
        <input type="text" name="EmployeeName" id="EmployeeName" class="search-query" placeholder="Search">
    }
</div>

<div class="btn-toolbar pull-left">
    @Html.ActionLink("Add new User", "Create", null, new{@class="btn"})
    @Html.ActionLink("Export", "Export", null, new{@class="btn"})
    @if (User.IsInRole("Developer"))
    {
        @Html.ActionLink("Invite Uninintialized", "InviteUninitialized", null, new{@class="btn"})
    }
</div>
    
<div id="users-online">Users online now: <span class="badge badge-info">@Membership.GetNumberOfUsersOnline()</span></div>

@grid.GetHtml(columns:
        grid.Columns(
                grid.Column("FullName", "Full Name"),
                grid.Column("Username", format:  
                                    @<text>
                                         <span title="@Html.Encode(item.Email)">
                                             @Html.Encode(item.Username)
                                         </span>
                                         @Html.Partial("_UserStatusLabels", 
                                            new User{
                                                LastActivityDate = item.LastActivityDate,
                                                IsLockedOut = item.IsLockedOut,
                                                LastLockoutDate = item.LastLockoutDate,
                                                IsApproved = item.IsApproved})
                                     </text> ),
                grid.Column("Roles", format: 
                                    @<text>
                                    @{var roles = Roles.Provider.GetRolesForUser(item.Username);}
                                    @if (roles.Length > 0)
                                    {
                                        @Html.Encode(string.Join(", ", roles))
                                    }
                                    else
                                    {
                                        <span class='label label-warning'>No Role</span>
                                    }
                                    </text>),
                grid.Column("LastActivityDate", "Last Activity",
                            @<text>
                                 @Html.Partial("_DateTimeHistoric", new Tuple<DateTime,string>((DateTime)item.LastActivityDate, "No Activity"))
                            </text>),
                grid.Column(format:
                            @<div class='btn-group'>
                                @*Html.ActionLink("Edit", "Edit", new { id = item.UserId }, new { @class = "btn btn-mini" })*@
                                @Html.ActionLink("Details / Edit", "Details", new { id = item.UserId }, new { @class = "btn btn-mini" })
                            </div>)
            ), 
            htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
            numericLinksCount: 20
     )