

<?php $__env->startSection('title', 'لوحة تحكم النقاط والدعوات'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <!-- Header -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <h1 class="h3 mb-0 text-gray-800">
                    <i class="fas fa-star text-warning"></i>
                    لوحة تحكم النقاط والدعوات
                </h1>
                <div class="btn-group">
                    <a href="<?php echo e(route('admin.points.settings')); ?>" class="btn btn-outline-primary">
                        <i class="fas fa-cog"></i> الإعدادات
                    </a>
                    <a href="<?php echo e(route('admin.points.reports')); ?>" class="btn btn-outline-info">
                        <i class="fas fa-chart-bar"></i> التقارير
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- إحصائيات عامة -->
    <div class="row mb-4">
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-primary shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                                إجمالي النقاط
                            </div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">
                                <?php echo e(number_format($totalPoints)); ?>

                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-star fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-success shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                النقاط المتاحة
                            </div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">
                                <?php echo e(number_format($availablePoints)); ?>

                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-coins fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-info shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
                                الإحالات المكتملة
                            </div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">
                                <?php echo e($completedReferrals); ?>

                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-users fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-warning shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                                طلبات الاسترداد المعلقة
                            </div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">
                                <?php echo e($pendingRedemptions); ?>

                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-clock fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- إحصائيات إضافية -->
    <div class="row mb-4">
        <div class="col-lg-8">
            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">إحصائيات الفترة الأخيرة (30 يوم)</h6>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="text-center">
                                <div class="h4 text-success"><?php echo e(number_format($earnedPoints)); ?></div>
                                <div class="text-muted">نقاط مكتسبة</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="text-center">
                                <div class="h4 text-danger"><?php echo e(number_format($usedPointsRecent)); ?></div>
                                <div class="text-muted">نقاط مستخدمة</div>
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div class="row">
                        <div class="col-md-4">
                            <div class="text-center">
                                <div class="h5 text-info"><?php echo e($recentTransactions); ?></div>
                                <div class="text-muted">معاملات</div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="text-center">
                                <div class="h5 text-warning"><?php echo e($totalRedemptions); ?></div>
                                <div class="text-muted">طلبات استرداد</div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="text-center">
                                <div class="h5 text-primary"><?php echo e($activeRewards); ?></div>
                                <div class="text-muted">مكافآت نشطة</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">روابط سريعة</h6>
                </div>
                <div class="card-body">
                    <div class="list-group list-group-flush">
                        <a href="<?php echo e(route('admin.points.management')); ?>" class="list-group-item list-group-item-action">
                            <i class="fas fa-users text-primary"></i>
                            إدارة النقاط
                        </a>
                        <a href="<?php echo e(route('admin.points.rewards')); ?>" class="list-group-item list-group-item-action">
                            <i class="fas fa-gift text-success"></i>
                            إدارة المكافآت
                        </a>
                        <a href="<?php echo e(route('admin.points.redemptions')); ?>" class="list-group-item list-group-item-action">
                            <i class="fas fa-shopping-cart text-warning"></i>
                            طلبات الاسترداد
                        </a>
                        <a href="<?php echo e(route('admin.points.referrals')); ?>" class="list-group-item list-group-item-action">
                            <i class="fas fa-share-alt text-info"></i>
                            إدارة الإحالات
                        </a>
                        <a href="<?php echo e(route('admin.points.transactions')); ?>" class="list-group-item list-group-item-action">
                            <i class="fas fa-exchange-alt text-secondary"></i>
                            المعاملات
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- أفضل المستخدمين -->
    <div class="row mb-4">
        <div class="col-lg-6">
            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">أفضل المستخدمين (أكثر نقاط)</h6>
                </div>
                <div class="card-body">
                    <?php if($topUsers->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>المستخدم</th>
                                        <th>النقاط</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $topUsers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $userPoints): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e($index + 1); ?></td>
                                            <td>
                                                <div class="d-flex align-items-center">
                                                    <div class="mr-2">
                                                        <div class="bg-primary rounded-circle d-flex align-items-center justify-content-center" style="width: 30px; height: 30px;">
                                                            <span class="text-white font-weight-bold"><?php echo e(substr($userPoints->user->name, 0, 1)); ?></span>
                                                        </div>
                                                    </div>
                                                    <div>
                                                        <div class="font-weight-bold"><?php echo e($userPoints->user->name); ?></div>
                                                        <small class="text-muted"><?php echo e($userPoints->user->email); ?></small>
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <span class="badge badge-primary"><?php echo e(number_format($userPoints->points)); ?></span>
                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <div class="text-center text-muted py-3">
                            <i class="fas fa-users fa-3x mb-3"></i>
                            <p>لا توجد بيانات</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <div class="col-lg-6">
            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">أكثر الإحالات نجاحاً</h6>
                </div>
                <div class="card-body">
                    <?php if($topReferrers->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>المستخدم</th>
                                        <th>الإحالات</th>
                                        <th>النقاط</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $topReferrers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $referrer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e($index + 1); ?></td>
                                            <td>
                                                <div class="d-flex align-items-center">
                                                    <div class="mr-2">
                                                        <div class="bg-success rounded-circle d-flex align-items-center justify-content-center" style="width: 30px; height: 30px;">
                                                            <span class="text-white font-weight-bold"><?php echo e(substr($referrer->referrer->name, 0, 1)); ?></span>
                                                        </div>
                                                    </div>
                                                    <div>
                                                        <div class="font-weight-bold"><?php echo e($referrer->referrer->name); ?></div>
                                                        <small class="text-muted"><?php echo e($referrer->referrer->email); ?></small>
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <span class="badge badge-success"><?php echo e($referrer->total_referrals); ?></span>
                                            </td>
                                            <td>
                                                <span class="badge badge-warning"><?php echo e(number_format($referrer->total_points)); ?></span>
                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <div class="text-center text-muted py-3">
                            <i class="fas fa-share-alt fa-3x mb-3"></i>
                            <p>لا توجد إحالات</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <!-- المعاملات الحديثة -->
    <div class="row">
        <div class="col-lg-8">
            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">المعاملات الحديثة</h6>
                </div>
                <div class="card-body">
                    <?php if($recentTransactionsList->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>المستخدم</th>
                                        <th>النوع</th>
                                        <th>النقاط</th>
                                        <th>الوصف</th>
                                        <th>التاريخ</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $recentTransactionsList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td>
                                                <div class="d-flex align-items-center">
                                                    <div class="mr-2">
                                                        <div class="bg-info rounded-circle d-flex align-items-center justify-content-center" style="width: 25px; height: 25px;">
                                                            <span class="text-white font-weight-bold" style="font-size: 10px;"><?php echo e(substr($transaction->user->name, 0, 1)); ?></span>
                                                        </div>
                                                    </div>
                                                    <div>
                                                        <div class="font-weight-bold" style="font-size: 12px;"><?php echo e($transaction->user->name); ?></div>
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <?php if($transaction->type === 'earned'): ?>
                                                    <span class="badge badge-success">كسب</span>
                                                <?php elseif($transaction->type === 'used'): ?>
                                                    <span class="badge badge-danger">استخدام</span>
                                                <?php else: ?>
                                                    <span class="badge badge-secondary"><?php echo e($transaction->type); ?></span>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <span class="font-weight-bold <?php echo e($transaction->type === 'earned' ? 'text-success' : 'text-danger'); ?>">
                                                    <?php echo e($transaction->type === 'earned' ? '+' : ''); ?><?php echo e($transaction->points); ?>

                                                </span>
                                            </td>
                                            <td>
                                                <small class="text-muted"><?php echo e(Str::limit($transaction->description, 30)); ?></small>
                                            </td>
                                            <td>
                                                <small class="text-muted"><?php echo e($transaction->created_at->format('Y-m-d H:i')); ?></small>
                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <div class="text-center text-muted py-3">
                            <i class="fas fa-exchange-alt fa-3x mb-3"></i>
                            <p>لا توجد معاملات</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card shadow">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">طلبات الاسترداد الحديثة</h6>
                </div>
                <div class="card-body">
                    <?php if($recentRedemptions->count() > 0): ?>
                        <div class="list-group list-group-flush">
                            <?php $__currentLoopData = $recentRedemptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $redemption): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="list-group-item">
                                    <div class="d-flex justify-content-between align-items-start">
                                        <div>
                                            <div class="font-weight-bold"><?php echo e($redemption->user->name); ?></div>
                                            <small class="text-muted"><?php echo e($redemption->reward->name_ar); ?></small>
                                        </div>
                                        <div class="text-right">
                                            <div class="badge badge-<?php echo e($redemption->status === 'pending' ? 'warning' : ($redemption->status === 'approved' ? 'success' : 'danger')); ?>">
                                                <?php echo e($redemption->status === 'pending' ? 'معلق' : ($redemption->status === 'approved' ? 'موافق' : 'مرفوض')); ?>

                                            </div>
                                            <div class="small text-muted"><?php echo e($redemption->points_used); ?> نقطة</div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center text-muted py-3">
                            <i class="fas fa-shopping-cart fa-3x mb-3"></i>
                            <p>لا توجد طلبات استرداد</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?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/points/dashboard.blade.php ENDPATH**/ ?>