<?php $__env->startSection('title', 'لوحة التحكم'); ?>
<?php $__env->startSection('page-title', 'لوحة التحكم الرئيسية'); ?>
<?php $__env->startSection('page-icon', 'fas fa-tachometer-alt'); ?>

<?php $__env->startSection('content'); ?>

<div class="row g-3 mb-4">
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon gold">
                <i class="fas fa-users"></i>
            </div>
            <div class="stat-value"><?php echo e(number_format($stats['total_users'])); ?></div>
            <div class="stat-label">إجمالي المستخدمين</div>
        </div>
    </div>
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon blue">
                <i class="fas fa-route"></i>
            </div>
            <div class="stat-value"><?php echo e(number_format($stats['total_trips'])); ?></div>
            <div class="stat-label">إجمالي الرحلات</div>
        </div>
    </div>
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon green">
                <i class="fas fa-utensils"></i>
            </div>
            <div class="stat-value"><?php echo e(number_format($stats['total_restaurants'])); ?></div>
            <div class="stat-label">المطاعم</div>
        </div>
    </div>
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon orange">
                <i class="fas fa-building"></i>
            </div>
            <div class="stat-value"><?php echo e(number_format($stats['total_gas_offices'])); ?></div>
            <div class="stat-label">مكاتب الغاز</div>
        </div>
    </div>
</div>


<div class="row g-3 mb-4">
    <div class="col-12">
        <div class="card border-warning" style="border-width: 1px;">
            <div class="card-body d-flex flex-wrap align-items-center justify-content-between gap-3">
                <div>
                    <h6 class="mb-1 text-warning">
                        <i class="fas fa-database me-1"></i> نشر ملفات التخزين (Storage → Public)
                    </h6>
                    <p class="text-muted small mb-0">
                        يحاول إنشاء الرابط الرمزي <code>public/storage</code> → <code>storage/app/public</code>؛
                        وإن تعذّر ذلك على الاستضافة، يُنسخ المحتوى فعلياً إلى <code>public/storage</code> حتى تظهر الصور والملفات في المتصفح.
                    </p>
                </div>
                <form method="POST" action="<?php echo e(route('admin.storage.sync-to-public')); ?>"
                      onsubmit="return confirm('تأكيد نشر / تحديث ملفات التخزين في public؟');">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="btn btn-warning">
                        <i class="fas fa-upload me-1"></i> نشر إلى public
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>


<div class="row g-3 mb-4">
    
    <div class="col-xl-7">
        <div class="card h-100">
            <div class="card-header">
                <i class="fas fa-chart-line"></i>
                الإيرادات
            </div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-6 col-md-3">
                        <div class="revenue-item">
                            <div class="revenue-label">اليوم</div>
                            <div class="revenue-value" style="color: var(--green-400);"><?php echo e(number_format($revenue['today'], 0)); ?></div>
                            <div class="revenue-currency">دينار عراقي</div>
                        </div>
                    </div>
                    <div class="col-6 col-md-3">
                        <div class="revenue-item">
                            <div class="revenue-label">هذا الأسبوع</div>
                            <div class="revenue-value" style="color: var(--blue-400);"><?php echo e(number_format($revenue['week'], 0)); ?></div>
                            <div class="revenue-currency">دينار عراقي</div>
                        </div>
                    </div>
                    <div class="col-6 col-md-3">
                        <div class="revenue-item">
                            <div class="revenue-label">هذا الشهر</div>
                            <div class="revenue-value" style="color: var(--gold-400);"><?php echo e(number_format($revenue['month'], 0)); ?></div>
                            <div class="revenue-currency">دينار عراقي</div>
                        </div>
                    </div>
                    <div class="col-6 col-md-3">
                        <div class="revenue-item" style="border: 1px solid rgba(255,215,0,0.15);">
                            <div class="revenue-label">الإجمالي</div>
                            <div class="revenue-value" style="color: var(--gold-300);"><?php echo e(number_format($revenue['total'], 0)); ?></div>
                            <div class="revenue-currency">دينار عراقي</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    
    <div class="col-xl-5">
        <div class="card h-100">
            <div class="card-header">
                <i class="fas fa-info-circle"></i>
                إحصائيات إضافية
            </div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-4">
                        <div class="revenue-item">
                            <div class="revenue-label">السائقين</div>
                            <div class="revenue-value" style="color: var(--gold-300);"><?php echo e(number_format($stats['total_drivers'])); ?></div>
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="revenue-item">
                            <div class="revenue-label">الركاب</div>
                            <div class="revenue-value" style="color: var(--green-400);"><?php echo e(number_format($stats['total_passengers'])); ?></div>
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="revenue-item">
                            <div class="revenue-label">المركبات</div>
                            <div class="revenue-value" style="color: var(--blue-400);"><?php echo e(number_format($stats['total_vehicles'])); ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="row g-3 mb-4">
    
    <div class="col-xl-6">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <div>
                    <i class="fas fa-route"></i>
                    الرحلات الأخيرة
                </div>
                <a href="<?php echo e(route('admin.trips')); ?>" class="btn btn-primary btn-sm">عرض الكل</a>
            </div>
            <div class="card-body p-0">
                <?php if($recent_trips->count() > 0): ?>
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>السائق</th>
                                    <th>الراكب</th>
                                    <th>الحالة</th>
                                    <th>التاريخ</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $recent_trips; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trip): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td>
                                        <?php if($trip->driver): ?>
                                            <strong><?php echo e($trip->driver->name ?? 'غير محدد'); ?></strong>
                                            <?php if($trip->driver->phone): ?>
                                                <br><small><?php echo e($trip->driver->phone); ?></small>
                                            <?php endif; ?>
                                        <?php else: ?>
                                            <span style="color: var(--text-muted);">غير محدد</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if($trip->passenger): ?>
                                            <strong><?php echo e($trip->passenger->name ?? 'غير محدد'); ?></strong>
                                            <?php if($trip->passenger->phone): ?>
                                                <br><small><?php echo e($trip->passenger->phone); ?></small>
                                            <?php endif; ?>
                                        <?php else: ?>
                                            <span style="color: var(--text-muted);">غير محدد</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php switch($trip->status):
                                            case ('completed'): ?>
                                                <span class="badge badge-success">مكتملة</span>
                                                <?php break; ?>
                                            <?php case ('in_progress'): ?>
                                            <?php case ('active'): ?>
                                                <span class="badge badge-info">قيد التنفيذ</span>
                                                <?php break; ?>
                                            <?php case ('cancelled'): ?>
                                                <span class="badge badge-danger">ملغية</span>
                                                <?php break; ?>
                                            <?php default: ?>
                                                <span class="badge badge-warning">معلقة</span>
                                        <?php endswitch; ?>
                                    </td>
                                    <td>
                                        <span><?php echo e($trip->created_at->format('Y-m-d')); ?></span>
                                        <br><small><?php echo e($trip->created_at->format('H:i')); ?></small>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                <?php else: ?>
                    <div class="empty-state">
                        <i class="fas fa-route d-block"></i>
                        لا توجد رحلات حديثة
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    
    <div class="col-xl-6">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <div>
                    <i class="fas fa-shopping-cart"></i>
                    الطلبات الأخيرة
                </div>
                <div class="d-flex gap-2">
                    <a href="<?php echo e(route('admin.restaurants')); ?>" class="btn btn-success btn-sm">المطاعم</a>
                    <a href="<?php echo e(route('admin.gas')); ?>" class="btn btn-danger btn-sm">الغاز</a>
                </div>
            </div>
            <div class="card-body">
                <ul class="nav nav-tabs mb-3" role="tablist">
                    <li class="nav-item">
                        <a class="nav-link active" data-bs-toggle="tab" href="#food-orders">
                            <i class="fas fa-utensils me-1"></i> طلبات الطعام
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" data-bs-toggle="tab" href="#gas-orders">
                            <i class="fas fa-fire me-1"></i> طلبات الغاز
                        </a>
                    </li>
                </ul>

                <div class="tab-content">
                    
                    <div class="tab-pane fade show active" id="food-orders">
                        <?php if($recent_food_orders->count() > 0): ?>
                            <?php $__currentLoopData = $recent_food_orders->take(5); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="order-item">
                                <div class="flex-grow-1">
                                    <div class="order-title"><?php echo e($order->restaurant->name ?? 'مطعم غير محدد'); ?></div>
                                    <div class="order-meta">
                                        <i class="fas fa-user"></i> <?php echo e($order->user->name ?? 'غير محدد'); ?>

                                        <?php if($order->user && $order->user->phone): ?>
                                            &middot; <?php echo e($order->user->phone); ?>

                                        <?php endif; ?>
                                    </div>
                                    <div class="order-meta">
                                        <i class="fas fa-clock"></i> <?php echo e($order->created_at->format('Y-m-d H:i')); ?>

                                    </div>
                                </div>
                                <div class="text-end">
                                    <?php switch($order->status):
                                        case ('completed'): ?>
                                            <span class="badge badge-success">مكتمل</span>
                                            <?php break; ?>
                                        <?php case ('pending'): ?>
                                            <span class="badge badge-warning">معلق</span>
                                            <?php break; ?>
                                        <?php case ('cancelled'): ?>
                                            <span class="badge badge-danger">ملغي</span>
                                            <?php break; ?>
                                        <?php default: ?>
                                            <span class="badge badge-secondary"><?php echo e($order->status); ?></span>
                                    <?php endswitch; ?>
                                    <?php if(isset($order->total) && $order->total): ?>
                                        <div class="order-meta mt-1"><?php echo e(number_format($order->total, 0)); ?> د.ع</div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php else: ?>
                            <div class="empty-state">
                                <i class="fas fa-utensils d-block"></i>
                                لا توجد طلبات طعام حديثة
                            </div>
                        <?php endif; ?>
                    </div>

                    
                    <div class="tab-pane fade" id="gas-orders">
                        <?php if($recent_gas_orders->count() > 0): ?>
                            <?php $__currentLoopData = $recent_gas_orders->take(5); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="order-item">
                                <div class="flex-grow-1">
                                    <div class="order-title">
                                        <i class="fas fa-fire" style="color: var(--orange-400); margin-left: 4px;"></i>
                                        طلب غاز
                                        <?php if($order->gasOffice): ?>
                                            &middot; <?php echo e($order->gasOffice->name ?? 'مكتب غير محدد'); ?>

                                        <?php endif; ?>
                                    </div>
                                    <div class="order-meta">
                                        <i class="fas fa-user"></i> <?php echo e($order->customer->name ?? 'غير محدد'); ?>

                                        <?php if($order->customer && $order->customer->phone): ?>
                                            &middot; <?php echo e($order->customer->phone); ?>

                                        <?php endif; ?>
                                    </div>
                                    <div class="order-meta">
                                        <i class="fas fa-clock"></i> <?php echo e($order->created_at->format('Y-m-d H:i')); ?>

                                    </div>
                                </div>
                                <div class="text-end">
                                    <?php switch($order->status):
                                        case ('completed'): ?>
                                            <span class="badge badge-success">مكتمل</span>
                                            <?php break; ?>
                                        <?php case ('pending'): ?>
                                            <span class="badge badge-warning">معلق</span>
                                            <?php break; ?>
                                        <?php case ('cancelled'): ?>
                                            <span class="badge badge-danger">ملغي</span>
                                            <?php break; ?>
                                        <?php default: ?>
                                            <span class="badge badge-secondary"><?php echo e($order->status); ?></span>
                                    <?php endswitch; ?>
                                    <?php if(isset($order->total) && $order->total): ?>
                                        <div class="order-meta mt-1"><?php echo e(number_format($order->total, 0)); ?> د.ع</div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php else: ?>
                            <div class="empty-state">
                                <i class="fas fa-fire d-block"></i>
                                لا توجد طلبات غاز حديثة
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="row g-3">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <i class="fas fa-chart-area"></i>
                الإيرادات الشهرية
            </div>
            <div class="card-body">
                <canvas id="revenueChart" height="80"></canvas>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const ctx = document.getElementById('revenueChart').getContext('2d');

    // Gradient fill
    const gradient = ctx.createLinearGradient(0, 0, 0, 300);
    gradient.addColorStop(0, 'rgba(255, 215, 0, 0.2)');
    gradient.addColorStop(1, 'rgba(255, 215, 0, 0)');

    new Chart(ctx, {
        type: 'line',
        data: {
            labels: ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'],
            datasets: [{
                label: 'الإيرادات (دينار عراقي)',
                data: <?php echo json_encode($monthly_revenue ?? array_fill(0, 12, $revenue['month'])) ?>,
                borderColor: '#FFD700',
                backgroundColor: gradient,
                borderWidth: 2.5,
                pointBackgroundColor: '#FFD700',
                pointBorderColor: '#0B0E18',
                pointBorderWidth: 2,
                pointRadius: 4,
                pointHoverRadius: 7,
                tension: 0.4,
                fill: true,
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: true,
            interaction: {
                intersect: false,
                mode: 'index',
            },
            plugins: {
                legend: {
                    display: false,
                },
                tooltip: {
                    backgroundColor: '#1E2440',
                    titleColor: '#F0F1F5',
                    bodyColor: '#FFD700',
                    borderColor: 'rgba(255,215,0,0.2)',
                    borderWidth: 1,
                    cornerRadius: 8,
                    padding: 12,
                    titleFont: { family: 'Tajawal', size: 13, weight: '600' },
                    bodyFont: { family: 'Tajawal', size: 14, weight: '700' },
                    displayColors: false,
                    callbacks: {
                        label: function(context) {
                            return new Intl.NumberFormat('ar-IQ').format(context.raw) + ' دينار';
                        }
                    }
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    grid: {
                        color: 'rgba(255,255,255,0.04)',
                        drawBorder: false,
                    },
                    ticks: {
                        color: '#6B7394',
                        font: { family: 'Tajawal', size: 11 },
                        callback: function(value) {
                            return new Intl.NumberFormat('ar-IQ', { notation: 'compact' }).format(value);
                        }
                    },
                    border: { display: false }
                },
                x: {
                    grid: { display: false },
                    ticks: {
                        color: '#6B7394',
                        font: { family: 'Tajawal', size: 11 },
                    },
                    border: { display: false }
                }
            }
        }
    });
});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\taxi_app\resources\views/admin/dashboard.blade.php ENDPATH**/ ?>