@extends('layouts.admin')

@section('title', 'Roles')

@section('content')
    <section class="dashboard-head">
        <div>
            <span class="eyebrow">Admin</span>
            <h1>Roles</h1>
        </div>
        <a class="button primary" href="{{ route('admin.roles.create') }}">Add role</a>
    </section>

    @if (session('status'))
        <p class="form-status">{{ session('status') }}</p>
    @endif

    <section class="panel">
        <div class="table-wrap">
            <table>
                <thead>
                    <tr>
                        <th>Role</th>
                        <th>Users</th>
                        <th>Permissions</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($roles as $role)
                        <tr>
                            <td><strong>{{ $role->name }}</strong><small>{{ $role->slug }}</small></td>
                            <td>{{ $role->admin_users_count }}</td>
                            <td>{{ $role->permissions_count }}</td>
                            <td>
                                <div class="table-actions">
                                    <a class="text-button" href="{{ route('admin.roles.edit', $role) }}">Edit</a>
                                    <form method="POST" action="{{ route('admin.roles.destroy', $role) }}" onsubmit="return confirm('Delete this role?')">
                                        @csrf
                                        @method('DELETE')
                                        <button class="text-button danger" type="submit">Delete</button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="4">No roles available.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </section>
@endsection
