@extends('admin.layouts.app')

@section('title', 'إدارة المحافظات')
@section('page-title', 'إدارة المحافظات')
@section('page-icon', 'fas fa-map-marked-alt')

@section('content')
<div class="row g-3 mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <div>
                    <i class="fas fa-map-marked-alt"></i>
                    قائمة المحافظات
                </div>
                <a href="{{ route('admin.governorates.create') }}" class="btn btn-primary btn-sm">
                    <i class="fas fa-plus"></i> إضافة محافظة جديدة
                </a>
            </div>
            <div class="card-body p-0">
                @if($governorates->count() > 0)
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>الاسم بالعربية</th>
                                    <th>الاسم بالإنجليزية</th>
                                    <th>الرمز</th>
                                    <th>عدد المدن</th>
                                    <th>الإحداثيات</th>
                                    <th>الترتيب</th>
                                    <th>الحالة</th>
                                    <th>الإجراءات</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($governorates as $governorate)
                                    <tr>
                                        <td>{{ $governorate->id }}</td>
                                        <td>{{ $governorate->name_ar }}</td>
                                        <td>{{ $governorate->name_en }}</td>
                                        <td>
                                            <span class="badge badge-info">{{ $governorate->code }}</span>
                                        </td>
                                        <td>
                                            <span class="badge badge-secondary">{{ $governorate->cities_count }}</span>
                                        </td>
                                        <td>
                                            @if($governorate->latitude && $governorate->longitude)
                                                <small style="color: var(--text-muted);">
                                                    {{ $governorate->latitude }}, {{ $governorate->longitude }}
                                                </small>
                                            @else
                                                <span style="color: var(--text-muted);">غير محدد</span>
                                            @endif
                                        </td>
                                        <td>{{ $governorate->sort_order }}</td>
                                        <td>
                                            @if($governorate->is_active)
                                                <span class="badge badge-success">نشط</span>
                                            @else
                                                <span class="badge badge-danger">غير نشط</span>
                                            @endif
                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                <a href="{{ route('admin.governorates.show', $governorate) }}"
                                                   class="btn btn-info btn-sm" title="عرض">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                                <a href="{{ route('admin.governorates.edit', $governorate) }}"
                                                   class="btn btn-warning btn-sm" title="تعديل">
                                                    <i class="fas fa-edit"></i>
                                                </a>
                                                <form action="{{ route('admin.governorates.toggle-status', $governorate) }}"
                                                      method="POST" class="d-inline">
                                                    @csrf
                                                    @method('PATCH')
                                                    <button type="submit" class="btn btn-{{ $governorate->is_active ? 'secondary' : 'success' }} btn-sm"
                                                            title="{{ $governorate->is_active ? 'إلغاء التفعيل' : 'تفعيل' }}">
                                                        <i class="fas fa-{{ $governorate->is_active ? 'pause' : 'play' }}"></i>
                                                    </button>
                                                </form>
                                                <form action="{{ route('admin.governorates.destroy', $governorate) }}"
                                                      method="POST" class="d-inline"
                                                      onsubmit="return confirm('هل أنت متأكد من حذف هذه المحافظة؟')">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="btn btn-danger btn-sm" title="حذف">
                                                        <i class="fas fa-trash"></i>
                                                    </button>
                                                </form>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="p-3 border-top" style="border-color: rgba(255,255,255,0.04) !important;">
                        {{ $governorates->links() }}
                    </div>
                @else
                    <div class="empty-state">
                        <i class="fas fa-map-marked-alt d-block"></i>
                        لا توجد محافظات
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
