<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">
    <h1>Users</h1>

    <table class="table table-striped table-bordered">
        <caption data-ng-show="users" class="hidden">Table of realm users</caption>
        <thead>
        <tr>
            <th colspan="{{access.impersonation == true ? '8' : '7'}}">
                <div class="form-inline">
                    <div class="form-group">
                        <div class="input-group">
                            <input type="text" placeholder="Search..." data-ng-model="query.search" class="form-control search" onkeydown="if (event.keyCode == 13) document.getElementById('userSearch').click()">
                            <div class="input-group-addon">
                                    <i class="fa fa-search" id="userSearch" data-ng-click="firstPage()"></i>
                            </div>
                        </div>
                    </div>
                    <button id="viewAllUsers" class="btn btn-default" ng-click="query.search = null; firstPage()">View all users</button>

                    <div class="pull-right" data-ng-show="access.manageUsers">
                        <button data-ng-click="unlockUsers()" class="btn btn-default">Unlock Users</button>
                        <a id="createUser" class="btn btn-default" href="#/create/user/{{realm.realm}}">Add User</a>
                    </div>
                </div>
            </th>
        </tr>
        <tr>
        <tr data-ng-show="searchLoaded && users.length > 0">
            <th class="w-15">ID</th>
            <th class="w-15">Username</th>
            <th class="w-15">Email</th>
            <th class="w-15">Last Name</th>
            <th class="w-15">First Name</th>
            <th colspan="{{access.impersonation == true ? '3' : '2'}}">Actions</th>
        </tr>
        </tr>
        </thead>
        <tfoot data-ng-show="users && (users.length >= query.max || query.first > 0)">
        <tr>
            <td colspan="7">
                <div class="table-nav">
                    <button data-ng-click="firstPage()" class="first" ng-disabled="query.first == 0">First page</button>
                    <button data-ng-click="previousPage()" class="prev" ng-disabled="query.first == 0">Previous page</button>
                    <button data-ng-click="nextPage()" class="next" ng-disabled="users.length < query.max">Next page</button>
                </div>
            </td>
        </tr>
        </tfoot>
        <tbody>
        <tr ng-repeat="user in users">
            <td class="clip"><a href="#/realms/{{realm.realm}}/users/{{user.id}}">{{user.id}}</a></td>
            <td class="clip">{{user.username}}</td>
            <td class="clip">{{user.email}}</td>
            <td class="clip">{{user.lastName}}</td>
            <td class="clip">{{user.firstName}}</td>
            <td class="kc-action-cell">
                <button class="btn btn-default btn-block btn-sm" kc-open="/realms/{{realm.realm}}/users/{{user.id}}">Edit</button>
            </td>
            <td data-ng-show="access.impersonation" class="kc-action-cell">
                <button class="btn btn-default btn-block btn-sm" data-ng-click="impersonate(user.id)">Impersonate</button>
            </td>
            <td data-ng-show="access.manageUsers" class="kc-action-cell">
                <button class="btn btn-default btn-block btn-sm" data-ng-click="removeUser(user)">Delete</button>
            </td>
        </tr>
        <tr data-ng-show="!users || users.length == 0">
            <td class="text-muted" data-ng-show="!users">Please enter a search, or click on view all users</td>
            <td class="text-muted" data-ng-show="searchLoaded && users.length == 0 && lastSearch != null">No results</td>
            <td class="text-muted" data-ng-show="searchLoaded && users.length == 0 && lastSearch == null">No users available</td>
        </tr>
        </tbody>
    </table>
</div>

<kc-menu></kc-menu>