<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">
    <h1>
        <span>Events</span>
        <kc-tooltip>Displays saved events for the realm. Events are related to user accounts, for example a user login. To enable persisted events go to config.</kc-tooltip>
    </h1>

    <ul class="nav nav-tabs">
        <li data-ng-class="(path[2] == 'events') && 'active'"><a href="#/realms/{{realm.realm}}/events">Login Events</a></li>
        <li data-ng-class="(path[2] == 'admin-events') && 'active'"><a href="#/realms/{{realm.realm}}/admin-events">Admin Events</a></li>
        <li data-ng-class="(path[2] == 'events-settings') && 'active'"><a href="#/realms/{{realm.realm}}/events-settings">Config</a></li>
    </ul>

    <table class="table table-striped table-bordered">
        <thead>
        <tr>
            <th class="kc-table-actions" colspan="4">
                <div class="pull-right">
                    <select data-ng-model="query.max" data-ng-click="update()" class="btn btn-default">
                        <option>5</option>
                        <option>10</option>
                        <option>50</option>
                        <option>100</option>
                    </select>
                    <button class="btn btn-default" data-ng-click="filter = !filter">
                        <span class="glyphicon glyphicon-plus" data-ng-show="!filter"></span>
                        <span class="glyphicon glyphicon-minus" data-ng-show="filter"></span>
                        Filter
                    </button>
                    <button class="btn btn-default btn-default" data-ng-click="update()">Update</button>
                    <button class="btn btn-default btn-default" data-ng-click="reset()">Reset</button>
                </div>
                <form class="form-horizontal">
                    <div class="form-group" data-ng-show="filter">
                <label class="col-md-2 control-label" for="eventTypes">Event Type</label>
                        <div class="col-sm-5">
                            <input ui-select2="eventSelectOptions" id="eventTypes" ng-model="query.type" data-placeholder="Select event types..."/>
            </div>
        </div>
                    <div class="form-group" data-ng-show="filter">
                        <label class="col-md-2 control-label" for="client">Client</label>
                        <div class="col-md-6">
                            <input class="form-control" type="text" id="client" name="client" data-ng-model="query.client">
                        </div>
                    </div>
                    <div class="form-group" data-ng-show="filter">
                        <label class="col-md-2 control-label" for="user">User</label>
                        <div class="col-md-6">
                            <input class="form-control" type="text" id="user" name="user" data-ng-model="query.user">
                        </div>
                    </div>

                    <div class="form-group" data-ng-show="filter">
                        <label class="col-md-2 control-label" for="dateFrom">Date (From)</label>
                        <div class="col-md-6">
                            <input class="form-control" type="text" id="dateFrom" name="dateFrom" data-ng-model="query.dateFrom" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                    <div class="form-group" data-ng-show="filter">
                        <label class="col-md-2 control-label" for="dateTo">Date (To)</label>
                        <div class="col-md-6">
                            <input class="form-control" type="text" id="dateTo" name="dateTo" data-ng-model="query.dateTo" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                </form>
            </th>
        </tr>
        <tr>
            <th width="100px">Time</th>
            <th width="180px">Event Type</th>
            <th>Details</th>
        </tr>
        </thead>
        <tfoot>
        <tr>
            <td colspan="7">
                <button data-ng-click="firstPage()" class="first" ng-disabled="query.first == 0"><i data-ng-class="query.first == 0 && 'text-muted'" class="fa fa-angle-double-left"></i></button>
                <button data-ng-click="previousPage()" class="prev" ng-disabled="query.first == 0"><i data-ng-class="query.first == 0 && 'text-muted'" class="fa fa-angle-left"></i></button>
                <button data-ng-click="nextPage()" class="next" ng-disabled="events.length < query.max"><i data-ng-class="events.length < query.max && 'text-muted'" class="fa fa-angle-right"></i></button>
            </td>
        </tr>
        </tfoot>
        <tbody>
            <tr ng-repeat="event in events">
                <td>{{event.time|date:'shortDate'}}<br>{{event.time|date:'mediumTime'}}</td>
                <td>{{event.type}}</td>
                <td>
                    <table class="table table-striped table-bordered">
                        <tr><td width="100px">Client</td><td>{{event.clientId}}</td></tr>
                        <tr><td>User</td><td>{{event.userId}}</td></tr>
                        <tr><td>IP Address</td><td>{{event.ipAddress}}</td></tr>
                        <tr data-ng-show="event.error"><td>Error</td><td>{{event.error}}</td></tr>
                        <tr>
                            <td>Details</td>
                            <td>
                                <button type="button" class="btn btn-default btn-xs" ng-click="event.collapse = !event.collapse">
                                    <span class="glyphicon glyphicon-plus" data-ng-show="!event.collapse"></span>
                                    <span class="glyphicon glyphicon-minus" data-ng-show="event.collapse"></span>
                                </button>
                                <table data-ng-show="event.collapse" class="table table-striped table-bordered">
                                    <tr ng-repeat="(key, value) in event.details">
                                        <td>{{key}}</td>
                                        <td>{{value}}</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr data-ng-show="event.representation">
                            <td>Representation</td>
                            <td>
                                <button type="button" class="btn btn-default btn-xs" ng-click="collapseRep = !collapseRep">
                                    <span class="glyphicon glyphicon-plus" data-ng-show="!collapseRep"></span>
                                    <span class="glyphicon glyphicon-minus" data-ng-show="collapseRep"></span>
                                </button>
                                <pre data-ng-show="collapseRep">{{event.representation}}</pre>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
</div>

<kc-menu></kc-menu>