@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('General.Regions', __('إدارة المناطق')))

@section('content')
<div class="container m-auto p-4 py-6">
    <div class="flex justify-between items-center mb-6">
        <h2 class="text-2l font-bold text-gray-800">{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Regions', __('إدارة المناطق')) }}</h2>
        @permission('regions.create')
        <a href="{{ route('regions.create') }}" class="bg-primary-600 hover:bg-primary-700 text-white font-bold py-2 p-4 rounded-md flex items-center">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 ml-1" viewBox="0 0 20 20" fill="currentColor">
                <path fill-rule="evenodd" d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z" clip-rule="evenodd" />
            </svg>
            {{ \App\Helpers\TranslationHelper::transFromDatabase('General.AddRegion', __('إضافة منطقة جديدة')) }}
        </a>
        @endpermission
    </div>

    @if(session('success'))
    <div class="bg-green-100 border border-green-400 text-green-700 p-4 py-3 rounded relative mb-4" role="alert">
        <span class="block sm:inline">{{ session('success') }}</span>
    </div>
    @endif

    @if(session('error'))
    <div class="bg-red-100 border border-red-400 text-red-700 p-4 py-3 rounded relative mb-4" role="alert">
        <span class="block sm:inline">{{ session('error') }}</span>
    </div>
    @endif

    <div class="bg-white rounded-lg shadow-md overflow-hidden">
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('General.RegionName', __('اسم المنطقة')) }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('General.CityName', __('المدينة')) }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('General.CountryName', __('الدولة')) }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Companies.UserActions', __('الإجراءات')) }}
                        </th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @forelse($regions as $region)
                    <tr>
                        <td class="p-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-medium text-gray-900">{{ $region->name }}</div>
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">{{ $region->city->name ?? \App\Helpers\TranslationHelper::transFromDatabase('CommonMessages.NotSpecified', __('غير محدد')) }}</div>
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">{{ $region->city->country->name ?? \App\Helpers\TranslationHelper::transFromDatabase('CommonMessages.NotSpecified', __('غير محدد')) }}</div>
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                            <div class="flex items-center space-x-2 space-x-reverse">
                                @permission('regions.edit')
                                <a href="{{ route('regions.edit', $region) }}" class="text-blue-600 hover:text-blue-900 ml-2" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('CommonButtons.Edit', __('تعديل')) }}">
                                    <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                    </svg>
                                </a>
                                @endpermission
                                @permission('regions.delete')
                                <form action="{{ route('regions.destroy', $region) }}" method="POST" class="inline" onsubmit="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('CommonMessages.ConfirmDelete', __('هل أنت متأكد من الحذف؟')) }}');">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-600 hover:text-red-900" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('CommonButtons.Delete', __('حذف')) }}">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
                                        </svg>
                                    </button>
                                </form>
                                @endpermission
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="4" class="p-6 py-4 whitespace-nowrap text-center text-gray-500">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('General.NoRegions', __('لا توجد مناطق مسجلة حالياً')) }}
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
