@extends('layouts.app')

@section('content')

<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; margin-top: 15px;">
    <h2 style="color: #d4af37; font-size: 1.5rem; font-weight: bold;">
        {{ app()->getLocale() == 'ar' ? 'إدارة الفروع' : 'Manage Branches' }}
    </h2>
    <a href="{{ route('admin.branches.create') }}" style="background: #d4af37; color: black; padding: 0.5rem 1rem; border-radius: 0.5rem; text-decoration: none; font-size: 0.875rem; font-weight: bold;">
        {{ app()->getLocale() == 'ar' ? '+ فرع جديد' : '+ New Branch' }}
    </a>
</div>

<div class="py-12">
    <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
        @if(session('success'))
        <div class="mb-4 p-4 bg-green-900/20 border border-green-500 rounded-lg text-green-400">
            {{ session('success') }}
        </div>
        @endif

        <div class="bg-[#111] border border-gray-800 rounded-2xl overflow-hidden">
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead>
                        <tr class="border-b border-gray-800 bg-black/50">
                            <th class="px-6 py-4 text-right text-sm font-semibold text-[#d4af37]">{{ app()->getLocale() == 'ar' ? 'اسم الفرع' : 'Branch Name' }}</th>
                            <th class="px-6 py-4 text-right text-sm font-semibold text-[#d4af37]">{{ app()->getLocale() == 'ar' ? 'الكود' : 'Code' }}</th>
                            <th class="px-6 py-4 text-right text-sm font-semibold text-[#d4af37]">{{ app()->getLocale() == 'ar' ? 'المدينة' : 'City' }}</th>
                            <th class="px-6 py-4 text-right text-sm font-semibold text-[#d4af37]">{{ app()->getLocale() == 'ar' ? 'الحالة' : 'Status' }}</th>
                            <th class="px-6 py-4 text-right text-sm font-semibold text-[#d4af37]">{{ app()->getLocale() == 'ar' ? 'السيارات' : 'Cars' }}</th>
                            <th class="px-6 py-4 text-right text-sm font-semibold text-[#d4af37]">{{ app()->getLocale() == 'ar' ? 'الإجراءات' : 'Actions' }}</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-800">
                        @forelse($branches as $branch)
                        <tr class="hover:bg-black/30 transition-colors">
                            <td class="px-6 py-4 text-sm text-white font-medium">{{ $branch->name }}</td>
                            <td class="px-6 py-4 text-sm text-gray-400">{{ $branch->code }}</td>
                            <td class="px-6 py-4 text-sm text-gray-400">{{ $branch->city }}</td>
                            <td class="px-6 py-4 text-sm">
                                <span class="px-3 py-1 rounded-full text-xs font-bold {{ $branch->status == 'active' ? 'bg-green-900/30 text-green-400' : 'bg-red-900/30 text-red-400' }}">
                                    {{ $branch->status == 'active' ? (app()->getLocale() == 'ar' ? 'نشط' : 'Active') : (app()->getLocale() == 'ar' ? 'معطل' : 'Inactive') }}
                                </span>
                            </td>
                            <td class="px-6 py-4 text-sm text-gray-400">{{ $branch->employees_count }}</td>
                            <td class="px-6 py-4 text-sm space-x-2">
                                <a href="{{ route('admin.branches.show', $branch) }}" class="text-[#d4af37] hover:text-[#c9a227] font-bold">
                                    {{ app()->getLocale() == 'ar' ? 'عرض' : 'View' }}
                                </a>
                                <a href="{{ route('admin.branches.edit', $branch) }}" class="text-blue-400 hover:text-blue-300 font-bold">
                                    {{ app()->getLocale() == 'ar' ? 'تعديل' : 'Edit' }}
                                </a>
                                <form action="{{ route('admin.branches.destroy', $branch) }}" method="POST" class="inline" onsubmit="return confirm('{{ app()->getLocale() == 'ar' ? 'هل تريد حذف هذا الفرع؟' : 'Are you sure?' }}');">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-500 hover:text-red-400 font-bold">
                                        {{ app()->getLocale() == 'ar' ? 'حذف' : 'Delete' }}
                                    </button>
                                </form>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="px-6 py-8 text-center text-gray-400">
                                {{ app()->getLocale() == 'ar' ? 'لا توجد فروع' : 'No branches found' }}
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>

        {{ $branches->links() }}
    </div>
</div>

@endsection
