
<?php $__env->startSection('title', 'Credit Requests'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid py-4">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Credit Package Requests</h5>
                </div>
                <div class="card-body">
                    <?php if(session('success')): ?>
                        <div class="alert alert-success"><?php echo e(session('success')); ?></div>
                    <?php endif; ?>
                    
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Reseller</th>
                                    <th>Package</th>
                                    <th>Credits</th>
                                    <th>Amount Paid</th>
                                    <th>Payment Method</th>
                                    <th>Reference</th>
                                    <th>Proof of Payment</th>
                                    <th>Status</th>
                                    <th>Requested</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $requests; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $request): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($request->id); ?></td>
                                        <td><?php echo e($request->reseller->name ?? 'N/A'); ?></td>
                                        <td><?php echo e($request->creditPackage->name ?? 'N/A'); ?></td>
                                        <td><?php echo e(number_format($request->creditPackage->credits ?? 0, 2)); ?></td>
                                        <td><?php echo e(App\CPU\Helpers::formatCurrency($request->amount_paid)); ?></td>
                                        <td><?php echo e($request->payment_method ?? '-'); ?></td>
                                        <td><?php echo e($request->payment_reference ?? '-'); ?></td>
                                        <td>
                                            <?php if($request->proof_of_payment): ?>
                                                <a href="/pixy/public/storage/proof_of_payment/<?php echo e(basename($request->proof_of_payment)); ?>" target="_blank" class="btn btn-sm btn-info">
                                                    <i class="mdi mdi-image"></i> View
                                                </a>
                                            <?php else: ?>
                                                <span class="text-muted">-</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($request->status == 'pending'): ?>
                                                <span class="badge bg-warning">Pending</span>
                                            <?php elseif($request->status == 'approved'): ?>
                                                <span class="badge bg-success">Approved</span>
                                            <?php else: ?>
                                                <span class="badge bg-danger">Rejected</span>
                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo e($request->created_at->format('M d, Y H:i')); ?></td>
                                        <td>
                                            <?php if($request->status == 'pending'): ?>
                                                <button class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#approveModal<?php echo e($request->id); ?>">
                                                    <i class="mdi mdi-check"></i>
                                                </button>
                                                <button class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#rejectModal<?php echo e($request->id); ?>">
                                                    <i class="mdi mdi-close"></i>
                                                </button>
                                            <?php else: ?>
                                                <span class="text-muted">-</span>
                                            <?php endif; ?>
                                        </td>
                                    </tr>

                                    <!-- Approve Modal -->
                                    <div class="modal fade" id="approveModal<?php echo e($request->id); ?>" tabindex="-1">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <form action="<?php echo e(route('admin.credit.requests.approve', $request->id)); ?>" method="POST">
                                                    <?php echo csrf_field(); ?>
                                                    <div class="modal-header">
                                                        <h5 class="modal-title">Approve Request</h5>
                                                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                                    </div>
                                                    <div class="modal-body">
                                                        <p>Approve this credit request for <strong><?php echo e($request->reseller->name ?? 'N/A'); ?></strong>?</p>
                                                        <p>Package: <strong><?php echo e($request->creditPackage->name ?? 'N/A'); ?></strong></p>
                                                        <p>Credits: <strong><?php echo e(number_format($request->creditPackage->credits ?? 0, 2)); ?></strong></p>
                                                        <div class="mb-3">
                                                            <label class="form-label">Notes (optional)</label>
                                                            <textarea name="admin_notes" class="form-control" placeholder="Optional notes"></textarea>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="submit" class="btn btn-success">Approve</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Reject Modal -->
                                    <div class="modal fade" id="rejectModal<?php echo e($request->id); ?>" tabindex="-1">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <form action="<?php echo e(route('admin.credit.requests.reject', $request->id)); ?>" method="POST">
                                                    <?php echo csrf_field(); ?>
                                                    <div class="modal-header">
                                                        <h5 class="modal-title">Reject Request</h5>
                                                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                                    </div>
                                                    <div class="modal-body">
                                                        <p>Reject this credit request for <strong><?php echo e($request->reseller->name ?? 'N/A'); ?></strong>?</p>
                                                        <div class="mb-3">
                                                            <label class="form-label">Reason (optional)</label>
                                                            <textarea name="admin_notes" class="form-control" placeholder="Reason for rejection"></textarea>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="submit" class="btn btn-danger">Reject</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="11" class="text-center">No credit requests found.</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\pixy\resources\views/admin/credit_requests/index.blade.php ENDPATH**/ ?>