@extends('layouts.backend')

@section('content-header')
    <h1>
        Utilisateurs
        <small>{{ $users->total() }} utilisateurs</small>
    </h1>
@endsection
@section('content')
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h3 class="box-title">

                    </h3>

                    <div class="box-tools">
                        {!! Form::open(['route' => ['backend.users.index'], 'class' => 'form-inline', 'method' => 'GET']) !!}
                        <div class="input-group" style="width: 450px;">
                            {{ Form::select('role', $roles , null, ['class' => 'form-control select2', 'placeholder' => 'Sélectionnez un role...'])  }}
                        </div>
                        <div class="input-group">

                            <input type="text" name="q" class="form-control pull-right" placeholder="Recherche..." value="{{ request('q') }}" style="width: 300px;">

                            <div class="input-group-btn">
                                @if(request('q') || request('role'))
                                    <a href="{{ route('backend.users.index') }}" class="btn btn-danger"><i class="fa fa-times" aria-hidden="true"></i></a>
                                @endif
                                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                                <a href="{{ route('backend.users.create') }}" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> Ajouter utilisateur</a>
                            </div>
                        </div>
                        {!! Form::close() !!}

                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tbody><tr>
                            <th>ID</th>
                            <th>Nom</th>
                            <th>Email</th>
                            <th>Role</th>
                            <th style="width: 150px;" class="text-right">Action</th>
                        </tr>
                        @foreach($users as $user)
                        <tr>
                            <td>{{ $user->id }}</td>
                            <td>{{ $user->name }}</td>
                            <td>{{ $user->email }}</td>
                            <td>{{ $user->role->name }}</td>
                            <td class="text-right">
                                <a href="{{ route('backend.users.edit', $user->id) }}" class="btn btn-sm btn-primary"><i class="fa fa-edit" aria-hidden="true"></i></a>
                                <a href="{{ route('backend.users.delete', $user->id) }}" class="btn btn-sm btn-danger" data-confirm="delete"><i class="fa fa-trash" aria-hidden="true"></i></a>
                            </td>
                        </tr>
                        @endforeach

                        </tbody></table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer clearfix">
                    {{ $users->appends(['q' => request('q'), 'company' => request('company')])->links() }}
                </div>
            </div>
            <!-- /.box -->
        </div>
    </div>
@endsection