@extends('layouts.app')

@section('content')
<div class="container m-auto p-4 sm:p-6 lg:p-8">
    <div class="bg-white rounded-lg shadow-lg p-6">
        <h1 class="text-2xl font-bold text-gray-900 mb-6">ملخص المخازن</h1>

        <!-- إحصائيات شاملة -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
            <div class="bg-gradient-to-br from-blue-50 to-blue-100 rounded-lg p-6 border-l-4 border-blue-500">
                <div class="flex items-center justify-between">
                    <div>
                        <p class="text-gray-700 text-sm font-medium">إجمالي قيمة المخازن</p>
                        <p class="text-2xl font-bold text-blue-600 mt-2">{{ number_format($totalValue, 2) }}</p>
                    </div>
                    <i class="fas fa-money-bill-wave text-blue-300 text-3xl opacity-50"></i>
                </div>
            </div>

            <div class="bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg p-6 border-l-4 border-indigo-500">
                <div class="flex items-center justify-between">
                    <div>
                        <p class="text-gray-700 text-sm font-medium">إجمالي الكمية</p>
                        <p class="text-2xl font-bold text-indigo-600 mt-2">{{ number_format($totalQuantity, 2) }}</p>
                    </div>
                    <i class="fas fa-boxes text-indigo-300 text-3xl opacity-50"></i>
                </div>
            </div>

            <div class="bg-gradient-to-br from-green-50 to-green-100 rounded-lg p-6 border-l-4 border-green-500">
                <div class="flex items-center justify-between">
                    <div>
                        <p class="text-gray-700 text-sm font-medium">إجمالي الأصناف</p>
                        <p class="text-2xl font-bold text-green-600 mt-2">{{ $totalItems }}</p>
                    </div>
                    <i class="fas fa-barcode text-green-300 text-3xl opacity-50"></i>
                </div>
            </div>
        </div>

        <!-- جدول المخازن -->
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-700 uppercase tracking-wider">
                            اسم المخزن
                        </th>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-700 uppercase tracking-wider">
                            عدد الأصناف
                        </th>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-700 uppercase tracking-wider">
                            إجمالي الكمية
                        </th>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-700 uppercase tracking-wider">
                            إجمالي القيمة
                        </th>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-700 uppercase tracking-wider">
                            النسبة المئوية
                        </th>
                        <th class="px-6 py-3 text-right text-xs font-medium text-gray-700 uppercase tracking-wider">
                            الإجراءات
                        </th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @forelse($warehouses as $warehouse)
                    <tr class="hover:bg-gray-50 transition-colors">
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            <i class="fas fa-warehouse text-blue-500 ml-2"></i>
                            {{ $warehouse['name'] }}
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-600">
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium {{ $warehouse['items_count'] > 0 ? 'bg-blue-100 text-blue-700' : 'bg-gray-100 text-gray-500' }}">
                                {{ $warehouse['items_count'] }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm {{ $warehouse['total_quantity'] > 0 ? 'text-gray-900 font-medium' : 'text-gray-400' }}">
                            {{ number_format($warehouse['total_quantity'], 2) }}
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-semibold {{ $warehouse['total_value'] > 0 ? 'text-green-600' : 'text-gray-400' }}">
                            {{ number_format($warehouse['total_value'], 2) }}
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm">
                            <div class="flex items-center">
                                <div class="w-16 bg-gray-200 rounded-full h-2 mr-2">
                                    <div class="bg-blue-600 h-2 rounded-full" style="width: {{ $totalValue > 0 ? (($warehouse['total_value'] / $totalValue) * 100) : 0 }}%"></div>
                                </div>
                                <span class="text-gray-700 text-xs">
                                    @if($totalValue > 0)
                                        {{ number_format(($warehouse['total_value'] / $totalValue) * 100, 1) }}%
                                    @else
                                        0%
                                    @endif
                                </span>
                            </div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm">
                            <a href="{{ route('inventory.warehouses.show', $warehouse['id']) }}" class="inline-flex items-center px-3 py-1 rounded-md bg-blue-100 text-blue-600 hover:bg-blue-200 transition-colors text-xs font-medium">
                                <i class="fas fa-eye ml-1"></i>
                                عرض
                            </a>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="px-6 py-12 text-center">
                            <i class="fas fa-inbox text-4xl text-gray-300 mb-4 block"></i>
                            <p class="text-gray-500 text-sm">لا توجد مخازن للعرض</p>
                        </td>
                    </tr>
                    @endforelse
                </tbody>
                <tfoot class="bg-gray-50 border-t-2 border-gray-300">
                    <tr>
                        <td class="px-6 py-4 font-bold text-gray-900">الإجمالي</td>
                        <td class="px-6 py-4 font-bold text-gray-900">{{ $totalItems }}</td>
                        <td class="px-6 py-4 font-bold text-indigo-600">{{ number_format($totalQuantity, 2) }}</td>
                        <td class="px-6 py-4 font-bold text-green-600">{{ number_format($totalValue, 2) }}</td>
                        <td class="px-6 py-4 font-bold text-gray-900">100%</td>
                        <td></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>
@endsection
