@extends('layouts.app')

@section('content')
<div class="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 py-8 px-4 md:px-8">
    <div class="max-w-7xl mx-auto">
        <div class="mb-8">
            <div class="flex items-center justify-between mb-6">
                <div>
                    <h1 class="text-3xl font-bold text-gray-900 mb-2">🏷️ تقرير أنواع مراكز التكاليف</h1>
                    <p class="text-gray-600">عرض جميع أنواع مراكز التكاليف المعرفة بالنظام</p>
                </div>
                <div class="flex gap-2">
                    <a href="{{ request()->fullUrlWithQuery(['export' => 1]) }}" class="inline-flex items-center px-4 py-2 bg-green-600 text-white font-semibold rounded-lg hover:bg-green-700 transition-all duration-200 shadow-md">
                        <i class="fas fa-file-excel ml-2"></i>
                        <span>تصدير Excel</span>
                    </a>
                    <a href="{{ route('reports.cost-center') }}" class="inline-flex items-center px-4 py-2 bg-gray-600 text-white font-semibold rounded-lg hover:bg-gray-700 transition-all duration-200 shadow-md">
                        <i class="fas fa-arrow-right ml-2"></i>
                        <span>رجوع</span>
                    </a>
                </div>
            </div>

            <!-- Filters -->
            <div class="bg-white rounded-xl shadow-md p-6 mb-8 border border-gray-200">
                <form action="{{ route('reports.cost-center.types') }}" method="GET" class="grid grid-cols-1 md:grid-cols-4 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">من كود</label>
                        <input type="text" name="from_type" value="{{ $filters['from_type'] ?? '' }}" class="w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">إلى كود</label>
                        <input type="text" name="to_type" value="{{ $filters['to_type'] ?? '' }}" class="w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">الحالة</label>
                        <select name="status" class="w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                            <option value="">الكل</option>
                            <option value="active" {{ ($filters['status'] ?? '') == 'active' ? 'selected' : '' }}>نشط</option>
                            <option value="inactive" {{ ($filters['status'] ?? '') == 'inactive' ? 'selected' : '' }}>غير نشط</option>
                        </select>
                    </div>
                    <div class="flex items-end">
                        <button type="submit" class="w-full bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors shadow-sm font-semibold">
                            <i class="fas fa-filter ml-2"></i> تصفية
                        </button>
                    </div>
                </form>
            </div>
        </div>

        @if(empty($report))
        <div class="bg-white rounded-xl shadow-lg p-12 text-center border border-gray-200">
            <i class="fas fa-inbox text-gray-400 text-5xl mb-4"></i>
            <p class="text-gray-600 font-medium text-lg">لا توجد بيانات للعرض</p>
        </div>
        @else
        <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
            <div class="overflow-x-auto">
                <table class="w-full text-right">
                    <thead class="bg-gray-800 text-white">
                        <tr>
                            <th class="px-6 py-4 font-semibold text-sm">كود النوع</th>
                            <th class="px-6 py-4 font-semibold text-sm">اسم النوع</th>
                            <th class="px-6 py-4 font-semibold text-sm text-center">عدد الفئات التابعة</th>
                            <th class="px-6 py-4 font-semibold text-sm text-center">عدد مراكز التكلفة</th>
                            <th class="px-6 py-4 font-semibold text-sm text-center">الحالة</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        @foreach($report as $item)
                        <tr class="hover:bg-gray-50 transition-colors">
                            <td class="px-6 py-4 font-medium text-gray-900">{{ $item['code'] }}</td>
                            <td class="px-6 py-4 text-gray-700">{{ $item['name'] }}</td>
                            <td class="px-6 py-4 text-center">
                                <span class="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs font-bold">{{ $item['categories_count'] }}</span>
                            </td>
                            <td class="px-6 py-4 text-center">
                                <span class="bg-green-100 text-green-800 px-2 py-1 rounded text-xs font-bold">{{ $item['centers_count'] }}</span>
                            </td>
                            <td class="px-6 py-4 text-center">
                                <span class="px-3 py-1 rounded-full text-xs font-bold {{ $item['status'] == 'نشط' ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700' }}">
                                    {{ $item['status'] }}
                                </span>
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        @endif
    </div>
</div>
@endsection
