@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="{{ 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>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
            <!-- Count Cards -->
            <div class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 flex items-center gap-6">
                <div class="bg-blue-100 p-4 rounded-xl">
                    <i class="fas fa-tags text-blue-600 text-3xl"></i>
                </div>
                <div>
                    <p class="text-sm text-gray-500 font-medium">عدد الأنواع</p>
                    <p class="text-3xl font-bold text-gray-900">{{ $report['types_count'] }}</p>
                </div>
            </div>

            <div class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 flex items-center gap-6">
                <div class="bg-green-100 p-4 rounded-xl">
                    <i class="fas fa-folder-tree text-green-600 text-3xl"></i>
                </div>
                <div>
                    <p class="text-sm text-gray-500 font-medium">عدد الفئات</p>
                    <p class="text-3xl font-bold text-gray-900">{{ $report['categories_count'] }}</p>
                </div>
            </div>

            <div class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 flex items-center gap-6">
                <div class="bg-purple-100 p-4 rounded-xl">
                    <i class="fas fa-sitemap text-purple-600 text-3xl"></i>
                </div>
                <div>
                    <p class="text-sm text-gray-500 font-medium">عدد المراكز</p>
                    <p class="text-3xl font-bold text-gray-900">{{ $report['centers_count'] }}</p>
                </div>
            </div>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-12">
            <!-- Financial Summary -->
            <div class="bg-white rounded-2xl shadow-xl p-8 border border-gray-100">
                <h3 class="text-xl font-bold text-gray-900 mb-8 flex items-center">
                    <i class="fas fa-coins text-amber-500 ml-3"></i>
                    الأداء المالي الإجمالي
                </h3>
                <div class="space-y-6">
                    <div class="flex justify-between items-center p-4 bg-green-50 rounded-xl">
                        <span class="text-green-700 font-medium">إجمالي الإيرادات</span>
                        <span class="text-2xl font-bold text-green-700">{{ number_format($report['total_revenue'], 2) }} ر.س</span>
                    </div>
                    <div class="flex justify-between items-center p-4 bg-red-50 rounded-xl">
                        <span class="text-red-700 font-medium">إجمالي المصروفات</span>
                        <span class="text-2xl font-bold text-red-700">{{ number_format($report['total_expenses'], 2) }} ر.س</span>
                    </div>
                    <div class="border-t-2 border-dashed border-gray-100 pt-6">
                        <div class="flex justify-between items-center p-6 bg-gradient-to-r {{ $report['net_profit'] >= 0 ? 'from-blue-600 to-blue-700' : 'from-orange-600 to-orange-700' }} rounded-2xl text-white shadow-lg">
                            <span class="text-lg opacity-90 font-medium">صافي الربحية</span>
                            <span class="text-3xl font-black">{{ number_format($report['net_profit'], 2) }} ر.س</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Visualization -->
            <div class="bg-white rounded-2xl shadow-xl p-8 border border-gray-100 flex flex-col items-center justify-center">
                <h3 class="text-xl font-bold text-gray-900 mb-8 self-start">
                    <i class="fas fa-chart-pie text-indigo-500 ml-3"></i>
                    نسبة الربحية للمصروفات
                </h3>
                <div class="w-full h-64">
                    <canvas id="summaryChart"></canvas>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    const ctx = document.getElementById('summaryChart').getContext('2d');
    new Chart(ctx, {
        type: 'doughnut',
        data: {
            labels: ['المصروفات', 'صافي الربح'],
            datasets: [{
                data: [{{ $report['total_expenses'] }}, {{ max(0, $report['net_profit']) }}],
                backgroundColor: ['#EF4444', '#3B82F6'],
                hoverOffset: 4
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { position: 'bottom' }
            }
        }
    });
</script>
@endsection
