<!-- show the list of Events -->
<div class="container">
    <h1>{{'Events' | translate}}
        <button ng-click="$state.go('event.new')" class="btn btn-success">
            <span class="fa fa-plus-circle vcenter"></span>
            {{'Add event' | translate}}
        </button>
    </h1>
    <div class="panel panel-primary table-striped top5">
        <div class="panel-heading">{{'Events' | translate}}</div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <label for="query-events">{{'Search:' | translate}}</label>
                    <input eventman-focus type="text" id="query-events" class="form-control" placeholder="{{'Event title' | translate}}" ng-model="query" ng-model-options="{debounce: 600}">
                </div>
                <div class="form-group">
                    <label for="events-order">Sort by:</label>
                    <select id="events-order" class="form-control" ng-model="eventsOrderProp">
                        <option value="title">{{'Title' | translate}}</option>
                        <option value="-title">{{'Title (descending)' | translate}}</option>
                        <option value="begin_date">{{'Date' | translate}}</option>
                        <option value="-begin_date">{{'Date (descending)' | translate}}</option>
                    </select>
                </div>
            </form>

            <div ng-include=" 'modal-confirm-action.html' " class="hidden"></div>
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th><strong>{{'Event' | translate}}</strong></th>
                        <th ng-if="hasPermission('event|update')" class="hcenter"><strong>{{'Attendees / Registered' | translate}}</strong></th>
                        <th><strong>{{'Actions' | translate}}</strong></th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="event in events | splittedFilter:query | orderBy:eventsOrderProp">
                        <td>
                            <span><strong>{{event.title}}</strong></span>
                            <p>{{'Begins:' | translate}} {{event['begin-date'] | date:'fullDate'}} {{event['begin-time'] | date:'HH:mm'}}<br/>
                            {{'Ends:' | translate}} {{event['end-date'] | date:'fullDate' }} {{event['end-time'] | date:'HH:mm'}}</p>
                        </td>
                        <td ng-if="hasPermission('persons|read')" class="hcenter">
                            <p><span ng-init="attendeesNr = ((event.persons || []) | attendeesFilter).length">{{attendeesNr}}</span> / {{event.persons.length || 0}} ({{((attendeesNr / (event.persons.length || 0) * 100) || 0).toFixed()}}%)</p>
                        </td>
                        <td>
                            <button ng-if="hasPermission('event:tickets|create')" ng-click="$state.go('event.ticket.new', {id: event._id})" class="btn btn-link fa fa-user-plus" type="button" title="{{'Register' | translate}}"></button>
                            <button ng-if="hasPermission('persons|update')" ng-click="$state.go('event.info', {id: event._id})" class="btn btn-link fa fa-list" type="button" title="{{'Manage attendees' | translate}}"></button>
                            <button ng-if="hasPermission('event|delete')" ng-click="remove(event._id)" type="button" class="btn btn-link fa fa-trash fa-lg" title="{{'Delete' | translate}}"></button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
