<div class="bs-sidebar col-sm-3 " data-ng-include data-src="'partials/realm-menu.html'"></div>
<div id="content-area" class="col-sm-9" role="main">

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

    <div id="content">
        <ol class="breadcrumb">
            <li><a href="#/realms/{{realm.realm}}">{{realm.realm}}</a></li>
            <li><a href="#/realms/{{realm.realm}}">Audit</a></li>
            <li class="active">Social</li>
        </ol>
        <h2><span>{{realm.realm}}</span> Audit Log</h2>

        <table class="table">
            <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-primary" data-ng-click="update()">Update</button>
                    </div>
                    <form class="form-horizontal">
                        <div class="form-group" data-ng-show="filter">
                            <label class="col-sm-2 control-label" for="event">Event</label>
                            <div class="col-sm-4">
                                <input class="form-control" type="text" id="event" name="event" data-ng-model="query.event">
                            </div>
                        </div>
                        <div class="form-group" data-ng-show="filter">
                            <label class="col-sm-2 control-label" for="client">Client</label>
                            <div class="col-sm-4">
                                <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-sm-2 control-label" for="user">User</label>
                            <div class="col-sm-4">
                                <input class="form-control" type="text" id="user" name="user" data-ng-model="query.user">
                            </div>
                        </div>
                    </form>
                </th>
            </tr>
            <tr>
                <th width="100px">Time</th>
                <th width="180px">Event</th>
                <th>Details</th>
            </tr>
            </thead>
            <tfoot>
            <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="events.length < query.max">Next page</button>
                    </div>
                </td>
            </tr>
            </tfoot>
            <tbody>
                <tr ng-repeat="event in events">
                    <td>{{event.time|date:'shortDate'}}<br>{{event.time|date:'mediumTime'}}</td>
                    <td data-ng-class="event.error && 'audit-error' || 'audit-success'">{{event.event}}<br/>{{event.error}}</td>
                    <td>
                        <table>
                            <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>
                                <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">
                                        <tr ng-repeat="(key, value) in event.details">
                                            <td>{{key}}</td>
                                            <td>{{value}}</td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
</div>
