@extends('layouts.app')

@section('title', 'تقرير كفاءة المخازن')

@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">
        
        <!-- HEADER -->
        <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">
                        <i class="fas fa-tachometer-alt text-lime-600 ml-2"></i>كفاءة المخازن
                    </h1>
                    <p class="text-gray-600">مؤشرات أداء المخازن واستغلال المساحات والقيمة</p>
                </div>
                <div class="flex gap-2">
                    <button onclick="printReport()" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg transition-all duration-200">
                        <i class="fas fa-print mr-2"></i> طباعة
                    </button>
                    <button onclick="exportReport('pdf')" class="inline-flex items-center px-4 py-2 bg-red-600 hover:bg-red-700 text-white font-semibold rounded-lg transition-all duration-200">
                        <i class="fas fa-file-pdf mr-2"></i> PDF
                    </button>
                </div>
            </div>
        </div>

        <!-- STATS -->
        <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
            <div class="bg-white rounded-xl shadow-md p-6 border-b-4 border-blue-500">
                <p class="text-gray-600 text-sm font-medium mb-1">عدد المخازن</p>
                <p class="text-3xl font-bold text-gray-900">{{ $statistics['total_warehouses'] }}</p>
            </div>

            <div class="bg-white rounded-xl shadow-md p-6 border-b-4 border-green-500">
                <p class="text-gray-600 text-sm font-medium mb-1">متوسط الأصناف بالمخزن</p>
                <p class="text-3xl font-bold text-green-600">{{ number_format($statistics['avg_items_per_warehouse']) }}</p>
            </div>

            <div class="bg-white rounded-xl shadow-md p-6 border-b-4 border-yellow-500">
                <p class="text-gray-600 text-sm font-medium mb-1">متوسط درجة الكفاءة</p>
                <p class="text-3xl font-bold text-yellow-600">{{ number_format($statistics['avg_efficiency_score'], 1) }}%</p>
            </div>

            <div class="bg-white rounded-xl shadow-md p-6 border-b-4 border-purple-500">
                <p class="text-gray-600 text-sm font-medium mb-1">إجمالي القيمة المخزنة</p>
                <p class="text-3xl font-bold text-gray-900">{{ number_format($statistics['total_value'], 2) }} ريال</p>
            </div>
        </div>

        <!-- EFFICIENCY CARDS -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            @forelse($warehouseData as $warehouse)
            <div class="bg-white rounded-xl shadow-lg p-6 border border-gray-100 hover:shadow-xl transition-all duration-200 relative overflow-hidden group">
                <div class="absolute top-0 right-0 w-2 h-full bg-lime-500 group-hover:w-4 transition-all"></div>
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-xl font-bold text-gray-900">{{ $warehouse->name }}</h3>
                    <div class="text-xs font-mono bg-gray-100 text-gray-500 px-2 py-1 rounded">#{{ $warehouse->id }}</div>
                </div>

                <div class="space-y-4">
                    <div>
                        <div class="flex justify-between text-sm mb-1">
                            <span class="text-gray-500">مؤشر الكفاءة التشغيلية</span>
                            <span class="font-bold text-lime-600">{{ $warehouse->efficiency_score }}%</span>
                        </div>
                        <div class="w-full bg-gray-100 rounded-full h-3">
                            <div class="bg-lime-500 h-3 rounded-full transition-all duration-1000" style="width: {{ $warehouse->efficiency_score }}%"></div>
                        </div>
                    </div>

                    <div class="grid grid-cols-2 gap-4">
                        <div class="p-3 bg-gray-50 rounded-lg">
                            <p class="text-xs text-gray-500 mb-1">عدد الأصناف</p>
                            <p class="text-lg font-bold text-gray-800">{{ $warehouse->total_items }}</p>
                        </div>
                        <div class="p-3 bg-gray-50 rounded-lg">
                            <p class="text-xs text-gray-500 mb-1">الأصناف النشطة</p>
                            <p class="text-lg font-bold text-gray-800">{{ $warehouse->active_items ?? '-' }}</p>
                        </div>
                    </div>

                    <div class="pt-4 border-t border-gray-100 flex justify-between items-center">
                        <span class="text-sm text-gray-500">القيمة الإجمالية:</span>
                        <span class="text-lg font-bold text-blue-600">{{ number_format($warehouse->total_value, 2) }} ريال</span>
                    </div>
                </div>
            </div>
            @empty
            <div class="col-span-full py-20 text-center bg-white rounded-xl border-2 border-dashed border-gray-300">
                <i class="fas fa-warehouse text-gray-300 text-6xl mb-4"></i>
                <p class="text-gray-500 font-bold">لا توجد مخازن مضافة حالياً</p>
            </div>
            @endforelse
        </div>

    </div>
</div>

<script>
function printReport() { window.print(); }
function exportReport(format) {
    const params = new URLSearchParams({ report: 'warehouse-efficiency', format: format });
    window.location.href = '{{ route("inventory.reports.export") }}?' + params.toString();
}
</script>
@endsection
