@extends ('layouts.admin')
@section ('title')
SisVentas | Usuarios
@endsection
@section ('contenido')
<div class="row">
    <div class="col-12">
        <div class="page-title-box">
            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Inicio</a></li>
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Accesos</a></li>
                    <li class="breadcrumb-item active">Usuarios</li>
                </ol>
            </div>
            <h4 class="page-title">Administración de Usuarios</h4>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <div class="row mb-2">
                    <div class="col-sm-4">
                        @can('users-create')
                        <a href="{{ route('users.create') }}" class="btn btn-success mb-2"><i class="mdi mdi-plus-circle me-2"></i> Nuevo Usuario</a>
                        @endcan
                    </div>
                    <div class="col-sm-8">
                        <div class="text-sm-end">
                            <a href="{{url('reporteusuarios')}}" target="__blank" class="btn btn-danger mb-2"><i class="mdi mdi-printer"></i> Reporte</a>
                        </div>
                    </div><!-- end col-->
                </div>                
                <div class="table-responsive">
                    <table class="table table-centered w-100 dt-responsive nowrap table-bordered table-condensed table-hover"> 
                        <thead class="table-light">
                            <tr>
                                <th>Id</th>
                                <th>Nombres</th>
                                <th>Email</th>
                                <th>Roles</th>
                                <th style="width: 280px;">Acciones</th>
                            </tr>
                        </thead>
                        
                        <tbody>
                            @foreach ($data as $key => $user)
                            <tr>
                                <td>{{ $user->id }}</td>
                                <td>{{ $user->name }}</td>
                                <td>{{ $user->email }}</td>
                                <td>
                                    @if(!empty($user->getRoleNames()))
                                    @foreach($user->getRoleNames() as $val)
                                    <label class="badge bg-primary">{{ $val }}</label>
                                    @endforeach
                                    @endif
                                </td>
                                <td align="center">
                                    @can('user-show')
                                    <a href="{{ route('users.show',$user->id) }}"><button class="btn btn-primary"><i class="mdi mdi-eye"></i> Ver</button></a>
                                    @endcan
                                    @can('user-edit')
                                    <a href="{{ route('users.edit',$user->id) }}"><button class="btn btn-info"><i class="mdi mdi-square-edit-outline"></i> Editar</button></a>
                                    @endcan
                                    @can('user-delete')
                                    {!! Form::open(['method' => 'DELETE','route' => ['users.destroy', $user->id],'style'=>'display:inline']) !!}
                                    {!! Form::submit('Eliminar', ['class' => 'btn btn-danger']) !!}
                                    {!! Form::close() !!}
                                    @endcan
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                        
                    </table>
                    {{$data->render()}}
                </div>
            </div> <!-- end card-body-->
        </div> <!-- end card-->
    </div> <!-- end col -->
</div>

@push ('scripts')
<script>
    $('#liAcceso').addClass("side active");
    $('#aAcceso').addClass("active");
    $('#liUsuarios').addClass("active");
</script>
@endpush
@endsection