

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

<?php $__env->startSection('content'); ?>
<div class="content-wrapper">
    <div class="row">
        <div class="col-sm-12">
            <h4 class="mb-4">My Orders</h4>
        </div>
    </div>

    <!-- Tabs -->
    <ul class="nav nav-tabs mb-4" id="orderTabs" role="tablist">
        <li class="nav-item">
            <button class="nav-link active" id="user-orders-tab" data-bs-toggle="tab" data-bs-target="#user-orders" type="button">
                <i class="fa-solid fa-users"></i> User Orders
            </button>
        </li>
        <li class="nav-item">
            <button class="nav-link" id="credit-requests-tab" data-bs-toggle="tab" data-bs-target="#credit-requests" type="button">
                <i class="fa-solid fa-credit-card"></i> Credit Requests
                <?php if($creditRequests->where('status', 'pending')->count() > 0): ?>
                <span class="badge bg-warning ms-1"><?php echo e($creditRequests->where('status', 'pending')->count()); ?></span>
                <?php endif; ?>
            </button>
        </li>
    </ul>

    <div class="tab-content" id="orderTabsContent">
        <!-- User Orders Tab -->
        <div class="tab-pane fade show active" id="user-orders" role="tabpanel">
            <div class="row">
                <div class="col-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <!-- Search -->
                            <form method="GET" class="mb-4">
                                <div class="row">
                                    <div class="col-md-4">
                                        <input type="text" name="search" class="form-control" placeholder="Search by user name or email" value="<?php echo e(request('search')); ?>">
                                    </div>
                                    <div class="col-md-2">
                                        <button type="submit" class="btn btn-primary">Search</button>
                                    </div>
                                </div>
                            </form>

                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>Order ID</th>
                                            <th>User</th>
                                            <th>Plan</th>
                                            <th>Amount</th>
                                            <th>Payment Method</th>
                                            <th>Status</th>
                                            <th>Date</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__empty_1 = true; $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <tr>
                                            <td>#<?php echo e($order->id); ?></td>
                                            <td><?php echo e($order->user->name ?? 'N/A'); ?><br><small><?php echo e($order->user->email ?? ''); ?></small></td>
                                            <td><?php echo e($order->plan->name ?? 'N/A'); ?></td>
                                            <td><?php echo e(App\CPU\Helpers::formatCurrency($order->price)); ?></td>
                                            <td><?php echo e($order->payment_method ?? 'N/A'); ?></td>
                                            <td>
                                                <?php if($order->status == 'active'): ?>
                                                <span class="badge badge-success">Active</span>
                                                <?php elseif($order->status == 'expired'): ?>
                                                <span class="badge badge-danger">Expired</span>
                                                <?php else: ?>
                                                <span class="badge badge-warning"><?php echo e($order->status); ?></span>
                                                <?php endif; ?>
                                            </td>
                                            <td><?php echo e($order->created_at->format('Y-m-d')); ?></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr>
                                            <td colspan="7" class="text-center">No user orders found</td>
                                        </tr>
                                        <?php endif; ?>
                                    </tbody>
                                </table>
                            </div>

                            <div class="mt-4">
                                <?php echo e($orders->links()); ?>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Credit Requests Tab -->
        <div class="tab-pane fade" id="credit-requests" role="tabpanel">
            <div class="row">
                <div class="col-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Package</th>
                                            <th>Credits</th>
                                            <th>Amount</th>
                                            <th>Payment Method</th>
                                            <th>Reference</th>
                                            <th>Proof</th>
                                            <th>Status</th>
                                            <th>Date</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__empty_1 = true; $__currentLoopData = $creditRequests; $__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->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="fa-solid fa-image"></i>
                                                    </a>
                                                <?php else: ?>
                                                    <span class="text-muted">-</span>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <?php if($request->status == 'pending'): ?>
                                                <span class="badge badge-warning">Pending</span>
                                                <?php elseif($request->status == 'approved'): ?>
                                                <span class="badge badge-success">Approved</span>
                                                <?php else: ?>
                                                <span class="badge badge-danger">Rejected</span>
                                                <?php endif; ?>
                                            </td>
                                            <td><?php echo e($request->created_at->format('Y-m-d')); ?></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr>
                                            <td colspan="9" class="text-center">No credit requests found</td>
                                        </tr>
                                        <?php endif; ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.reseller', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\pixy\resources\views/reseller/orders.blade.php ENDPATH**/ ?>