﻿<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-l text-gray-800 leading-tight">
                {{ __('تفاصيل الدور') }}: {{ $role->name }}
            </h2>
            <div class="flex space-y-2 space-y-reverse">
                <a href="{{ route('roles.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 p-4 rounded">
                    العودة للقائمة
                </a>
                @permission('roles.edit')
                <a href="{{ route('roles.edit', $role) }}" class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-2 p-4 rounded">
                    تعديل
                </a>
                @endpermission
            </div>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7l m-auto sm:p-6 lg:p-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 bg-white border-b border-gray-200">
                    <div class="mb-6">
                        <h3 class="text-lg font-bold mb-2">معلومات الدور</h3>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <p class="text-gray-600">الاسم:</p>
                                <p class="font-semibold">{{ $role->name }}</p>
                            </div>
                            <div>
                                <p class="text-gray-600">الوصف:</p>
                                <p class="font-semibold">{{ $role->description ?: 'لا يوجد وصف' }}</p>
                            </div>
                            <div>
                                <p class="text-gray-600">الحالة:</p>
                                <p class="font-semibold">
                                    @if($role->is_active)
                                        <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                            نشط
                                        </span>
                                    @else
                                        <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                            غير نشط
                                        </span>
                                    @endif
                                </p>
                            </div>
                            <div>
                                <p class="text-gray-600">عدد المستخدمين:</p>
                                <p class="font-semibold">{{ $role->users->count() }}</p>
                            </div>
                        </div>
                    </div>

                    <div>
                        <h3 class="text-lg font-bold mb-2">الصلاحيات</h3>
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                            @foreach($permissions as $module => $modulePermissions)
                                <div class="border rounded p-4">
                                    <h4 class="font-bold text-md mb-2">{{ $module }}</h4>
                                    <ul class="list-disc list-inside">
                                        @foreach($modulePermissions as $permission)
                                            <li class="{{ in_array($permission->id, $rolePermissions) ? 'text-primary-600 font-semibold' : 'text-gray-500' }}">
                                                {{ $permission->display_name }}
                                            </li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
