<x-app-layout>
    @section('title')
        Staff Management
    @endsection
    <!-- Page Heading -->
    <h1 class="h3 mb-2 text-gray-800">

        @can('User create')
            <a href="{{ route('admin.users.create') }}" class="btn btn-primary"><i class="fas fa-plus" aria-hidden="true"></i>
                Create Staff
            </a>
        @endcan
    </h1>
    <!-- DataTales Example -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">
                Listing Staff Table
            </h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Roles</th>
                            <th>Created At</th>
                            <th>Updated At</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>

                        @can('User access')
                            @foreach ($users as $user)
                                <tr>
                                    <td>{{ $loop->index + 1 }}</td>
                                    <td>{{ $user->name }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td>
                                        @foreach ($user->roles as $role)
                                            <span class="badge badge-info mr-1">
                                                {{ $role->name }}
                                            </span>
                                        @endforeach
                                    </td>
                                    <td>{{ $user->created_at }}</td>
                                    <td>{{ $user->updated_at }}</td>
                                    <td class="d-flex">
                                        @can('User edit')
                                            <a href="{{ route('admin.users.edit', $user->id) }}"
                                                class="btn btn-primary btn-sm mr-1">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                        @endcan

                                        @can('User delete')
                                            <a href="{{ route('admin.users.destroy', $user->id) }}"
                                                class="btn btn-danger btn-sm" onclick="event.preventDefault();
                                                document.getElementById('user_delete').submit();"><i class="fas fa-trash"></i></a>
                                            <form id="user_delete" action="{{ route('admin.users.destroy', $user->id) }}"
                                            method="POST" class="inline d-none">
                                            @csrf
                                            @method('delete')
                                            <button
                                                class="btn btn-block bg-gradient-danger">Delete</button>
                                        </form>
                                        @endcan

                                    </td>
                                </tr>
                            @endforeach
                        @endcan
                    </tbody>
                </table>
            </div>
        </div>
    </div>


</x-app-layout>
