<?php $__env->startSection('title', 'طلبات شحن المحفظة'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid px-0">
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <h1 class="h3 mb-0" style="color: var(--text-light);">
                    <i class="fas fa-wallet" style="color: var(--primary-yellow);"></i>
                    طلبات شحن المحفظة
                </h1>
                <a href="<?php echo e(route('admin.dashboard')); ?>" class="btn btn-outline-primary">
                    <i class="fas fa-arrow-right"></i> العودة
                </a>
            </div>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success"><?php echo e(session('success')); ?></div>
    <?php endif; ?>
    <?php if(session('error')): ?>
        <div class="alert alert-danger"><?php echo e(session('error')); ?></div>
    <?php endif; ?>

    <div class="row mb-3">
        <div class="col-12">
            <div class="btn-group">
                <a href="<?php echo e(route('admin.wallet-topup.index', ['status' => 'pending'])); ?>" class="btn <?php echo e(($status ?? 'pending') == 'pending' ? 'btn-warning' : 'btn-outline-warning'); ?>">
                    قيد الانتظار
                </a>
                <a href="<?php echo e(route('admin.wallet-topup.index', ['status' => 'approved'])); ?>" class="btn <?php echo e(($status ?? '') == 'approved' ? 'btn-success' : 'btn-outline-success'); ?>">
                    مفعّلة
                </a>
                <a href="<?php echo e(route('admin.wallet-topup.index', ['status' => 'rejected'])); ?>" class="btn <?php echo e(($status ?? '') == 'rejected' ? 'btn-danger' : 'btn-outline-danger'); ?>">
                    مرفوضة
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <?php if($requests->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th style="color: var(--primary-yellow);">التاريخ</th>
                                        <th style="color: var(--primary-yellow);">النوع</th>
                                        <th style="color: var(--primary-yellow);">الاسم</th>
                                        <th style="color: var(--primary-yellow);">المبلغ</th>
                                        <th style="color: var(--primary-yellow);">كود التحويل</th>
                                        <th style="color: var(--primary-yellow);">رقم المحوّل منه</th>
                                        <th style="color: var(--primary-yellow);">صورة</th>
                                        <th style="color: var(--primary-yellow);">الحالة</th>
                                        <?php if(($status ?? 'pending') == 'pending'): ?>
                                        <th style="color: var(--primary-yellow);">إجراء</th>
                                        <?php endif; ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $requests; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($r->created_at->format('Y-m-d H:i')); ?></td>
                                        <td>
                                            <?php
                                                $ownerType = $r->partnerWallet?->owner_type ?? $r->owner_type ?? '';
                                            ?>
                                            <?php if($ownerType == 'restaurant'): ?>
                                                مطعم
                                            <?php elseif($ownerType == 'gas_office'): ?>
                                                مكتب غاز
                                            <?php elseif($ownerType == 'driver'): ?>
                                                سائق
                                            <?php else: ?>
                                                —
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($r->partnerWallet && $r->partnerWallet->owner): ?>
                                                <?php echo e($r->partnerWallet->owner->name ?? '—'); ?>

                                            <?php else: ?>
                                                —
                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo e(number_format($r->amount, 0)); ?> د.ع</td>
                                        <td><?php echo e($r->transfer_code ?? '—'); ?></td>
                                        <td><?php echo e($r->transfer_from_phone ?? '—'); ?></td>
                                        <td>
                                            <?php if($r->receipt_image_path): ?>
                                                <a href="<?php echo e(asset('storage/' . $r->receipt_image_path)); ?>" target="_blank" class="btn btn-sm btn-outline-info">عرض</a>
                                            <?php else: ?>
                                                —
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($r->status == 'pending'): ?>
                                                <span class="badge bg-warning">قيد الانتظار</span>
                                            <?php elseif($r->status == 'approved'): ?>
                                                <span class="badge bg-success">مفعّل</span>
                                            <?php else: ?>
                                                <span class="badge bg-danger">مرفوض</span>
                                            <?php endif; ?>
                                        </td>
                                        <?php if(($status ?? 'pending') == 'pending'): ?>
                                        <td>
                                            <form action="<?php echo e(route('admin.wallet-topup.approve', $r->id)); ?>" method="POST" class="d-inline">
                                                <?php echo csrf_field(); ?>
                                                <button type="submit" class="btn btn-sm btn-success" onclick="return confirm('تأكيد تفعيل الشحن وإضافة المبلغ للمحفظة؟')">
                                                    تفعيل
                                                </button>
                                            </form>
                                            <button type="button" class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#rejectModal<?php echo e($r->id); ?>">
                                                رفض
                                            </button>
                                            <div class="modal fade" id="rejectModal<?php echo e($r->id); ?>" tabindex="-1">
                                                <div class="modal-dialog">
                                                    <div class="modal-content" style="background: var(--card-bg); color: var(--text-light);">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title">رفض طلب الشحن</h5>
                                                            <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
                                                        </div>
                                                        <form action="<?php echo e(route('admin.wallet-topup.reject', $r->id)); ?>" method="POST">
                                                            <?php echo csrf_field(); ?>
                                                            <div class="modal-body">
                                                                <label class="form-label">سبب الرفض (اختياري)</label>
                                                                <textarea name="admin_notes" class="form-control" rows="2"></textarea>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button>
                                                                <button type="submit" class="btn btn-danger">رفض</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            </div>
                                        </td>
                                        <?php endif; ?>
                                    </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="d-flex justify-content-center mt-3">
                            <?php echo e($requests->links()); ?>

                        </div>
                    <?php else: ?>
                        <p class="text-muted mb-0">لا توجد طلبات.</p>
                    <?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/wallet-topup/index.blade.php ENDPATH**/ ?>