@extends('dashboard.layout')
@section('title', 'إدارة الأدوار')
@section('content')
    <div class="page-header">
        <h1>الأدوار</h1>
        <a href="{{ route('dashboard.roles.create') }}" class="btn btn-primary"><i class="fas fa-plus"></i> دور جديد</a>
    </div>
    <div class="card">
        <table>
            <thead>
                <tr>
                    <th>#</th>
                    <th>الاسم</th>
                    <th>الصلاحيات</th>
                    <th>الإجراءات</th>
                </tr>
            </thead>
            <tbody>
                @forelse($roles as $role)
                    <tr>
                        <td>{{ $role->id }}</td>
                        <td>{{ $role->name }}</td>
                        <td>
                            @forelse($role->permissions as $permission)
                                <span class="badge badge-success">{{ $permission->name }}</span>
                            @empty
                                <span class="badge badge-warning">بدون صلاحيات</span>
                            @endforelse
                        </td>
                        <td>
                            <div class="actions">
                                <a href="{{ route('dashboard.roles.edit', $role) }}" class="btn btn-warning btn-sm"><i class="fas fa-edit"></i></a>
                                @if($role->name !== 'super-admin')
                                    <form action="{{ route('dashboard.roles.destroy', $role) }}" method="POST" onsubmit="return confirm('تأكيد الحذف؟')">
                                        @csrf @method('DELETE')
                                        <button type="submit" class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </form>
                                @endif
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="4" style="text-align:center;color:#888;">لا يوجد أدوار</td></tr>
                @endforelse
            </tbody>
        </table>
        <div class="pagination">{{ $roles->links() }}</div>
    </div>
@endsection
