@extends('admin.layouts.main', [
    'scripts' => [path_asset('path.backoffice.js_path') . '/view/user/user-list.js'],
])

@section('content')
    <h1>{{ !empty($memberName) ? $memberName : '' }} Users</h1>
    <div id="users">
        <div class="list-filters-container">
            <label for="" class="list-filters-label">Filters:</label>
            <div class="list-filters">
                <div class="list-filter">
                    @php
                        $status = [
                            '' => 'Filter by Status',
                            'active' => 'Active',
                            'inactive' => 'Inactive',
                            'pendingApproval' => 'Pending Approval',
                            'block' => 'Block',
                        ];
                    @endphp
                    {!! Form::select('status_filter', $status, null, [
                        'id' => 'status_id_input',
                        'class' => 'form-control',
                    ]) !!}
                </div>
                <div class="list-filter">
                    @php
                        $commEmpty = [
                            0 => 'Filter by Committees',
                        ];
                        $committeesArray = array_merge($commEmpty, $committees);
                    @endphp
                    {!! Form::select('committees_filter', $committeesArray, null, [
                        'id' => 'committees_id_input',
                        'class' => 'form-control',
                    ]) !!}
                </div>
                <div class="list-filter">
                    @php
                        $wgEmpty = [
                            0 => 'Filter by WG / TF',
                        ];
                        $wg = array_merge($wgEmpty, $workGroups);
                    @endphp
                    {!! Form::select('wg_filter', $wg, null, [
                        'id' => 'wg_id_input',
                        'class' => 'form-control',
                    ]) !!}
                </div>
                <button type="button" data-toggle="tooltip" class="btn btn-default command-export list-export-btn"
                    title="Export to Excel">
                    <span class="icon glyphicon glyphicon-export"></span>
                </button>
                <form action="{{ url('/admin/member-usage/export') }}" method="GET" class="form-inline">
                    <input type="month" name="from" class="form-control"
                        value="{{ now()->tz('Europe/Berlin')->startOfMonth()->format('Y-m') }}"
                        aria-label="Usage report start month">
                    <input type="month" name="to" class="form-control"
                        value="{{ now()->tz('Europe/Berlin')->startOfMonth()->format('Y-m') }}" aria-label="Usage report end month">
                    <button type="submit" data-toggle="tooltip" class="btn btn-default"
                        title="Export member usage to Excel">
                        <span class="icon glyphicon glyphicon-stats"></span>
                    </button>
                </form>
            </div>
        </div>
        <table id="grid" class="table table-condensed table-hover table-striped">
            <thead>
                <tr>
                    <th data-column-id="id" data-type="numeric" data-sortable="true" data-identifier="true">ID</th>
                    <th data-column-id="name" data-order="asc">First Name</th>
                    <th data-column-id="last_name" data-sortable="true">Last Name</th>
                    <th data-column-id="email" data-sortable="true">Email</th>
                    <th data-column-id="member" data-formatter="member" data-sortable="false">Member</th>
                    <th data-column-id="department" data-sortable="true">Department</th>
                    <th data-column-id="function" data-sortable="true">Function</th>
                    <th data-column-id="created_at" data-order="asc">Registration Date</th>
                    <th data-column-id="state" data-sortable="false">State</th>
                    <th data-column-id="committees" data-sortable="false">Com / TF / WG</th>
                    @if ($canEdit)
                        <th data-column-id="commands" data-formatter="commands" data-sortable="false">
                            {{ trans('backend.actions') }}</th>
                    @endif
                </tr>
            </thead>
        </table>
    </div>
    <script>
        $(function() {
            var manageUsersView = new Eae.View.BackendUserList({
                el: $('#users'),
                userId: {{ $loggedUser->id }},
                memberId: {{ !empty($memberId) ? intval($memberId) : 0 }},
            });
        });
    </script>
@stop
