<?php if(!empty($getallorders) && is_array($getallorders)): ?>
    <?php foreach($getallorders as $product): ?>
        <?php if(!is_array($product) || !isset($product['id'])) continue; ?>
        <tr class="order-row" data-order-id="<?= $product['id'] ?>">
            <td class="align-middle">
                <div class="form-check">
                    <input class="form-check-input order-checkbox" type="checkbox" value="<?= $product['id'] ?>">
                </div>
            </td>
            <td class="align-middle">
                <span class="badge bg-primary">#<?= $product['id'] ?></span>
            </td>
            <td class="align-middle">
                <div class="d-flex align-items-center">
                    <div class="bg-primary bg-opacity-10 rounded-circle p-2 me-2">
                        <i class="bi bi-person text-primary"></i>
                    </div>
                    <div>
                        <div class="fw-semibold"><?= $product['username'] ?></div>
                        <?php if(!empty($product['user_type'])): ?>
                            <small class="text-muted"><?= __('admin.type_'. $product['user_type']) ?></small>
                        <?php endif; ?>
                    </div>
                </div>
            </td>
            <td class="align-middle">
                <?php if(!empty($product['user_type'])): ?>
                    <span class="badge bg-info"><?= __('admin.type_'. $product['user_type']) ?></span>
                <?php else: ?>
                    <span class="badge bg-secondary"><?= __('admin.standard') ?></span>
                <?php endif; ?>
            </td>
            <td class="align-middle text-end">
                <div class="fw-bold text-success"><?= c_format($product['total_sum']) ?></div>
            </td>
            <td class="align-middle">
                <?php
                $paymentIcon = 'bi-credit-card';
                $paymentClass = 'bg-info';
                $paymentText = str_replace("_", " ", $product['payment_method']);
                
                if ($product['payment_method'] == 'Bank Transfer') {
                    $paymentIcon = 'bi-bank';
                    $paymentClass = 'bg-primary';
                    $paymentText = __('admin.bank_transfer');
                } elseif ($product['payment_method'] == 'Cash On Delivery') {
                    $paymentIcon = 'bi-cash';
                    $paymentClass = 'bg-success';
                    $paymentText = __('admin.cash_on_delivery');
                } elseif ($product['payment_method'] == 'Paypal') {
                    $paymentIcon = 'bi-paypal';
                    $paymentClass = 'bg-warning';
                    $paymentText = __('admin.paypal');
                } elseif ($product['payment_method'] == 'Razorpay') {
                    $paymentIcon = 'bi-credit-card-2-front';
                    $paymentClass = 'bg-info';
                    $paymentText = __('admin.razorpay');
                } elseif ($product['payment_method'] == 'Flutterwave') {
                    $paymentIcon = 'bi-credit-card-fill';
                    $paymentClass = 'bg-secondary';
                    $paymentText = __('admin.flutterwave');
                }
                ?>
                <span class="badge <?= $paymentClass ?> text-white">
                    <i class="<?= $paymentIcon ?> me-1"></i><?= $paymentText ?>
                </span>
            </td>
            <td class="align-middle">
                <div class="d-flex align-items-center">
                    <?= $product['order_country_flag'] ?>
                    <small class="text-muted ms-1"><?= $product['ip'] ?? '' ?></small>
                </div>
            </td>
            <td class="align-middle">
                <?php if(!empty($product['txn_id'])): ?>
                    <code class="small"><?= substr($product['txn_id'], 0, 12) ?>...</code>
                <?php else: ?>
                    <span class="text-muted">-</span>
                <?php endif; ?>
            </td>
            <td class="align-middle text-end">
                <div class="mb-1">
                    <?php if($product['wallet_commission_status'] == 0): ?>
                        <span class="badge <?= ((int)$product['wallet_status'] > 0) ? 'bg-success' : 'bg-warning' ?>">
                            <?php  
                                if ($wallet_status[(int)$product['wallet_status']] == 'ON HOLD') {
                                    echo __('admin.onhold');
                                } elseif ($wallet_status[(int)$product['wallet_status']] == 'IN WALLET') {
                                    echo __('admin.inwallet');
                                } else {
                                    echo $wallet_status[(int)$product['wallet_status']];
                                }
                            ?>
                        </span>
                    <?php else: ?>
                        <?= commission_status($product['wallet_commission_status']) ?>
                    <?php endif; ?>
                </div>
                <div class="fw-semibold text-success"><?= c_format($product['commission_amount']) ?></div>
            </td>
            <td class="align-middle text-center">
                <div class="order-status">
                    <?php
                    $statusClass = 'bg-secondary';
                    $statusText = $status[$product['status']];
                    
                    if ($status[$product['status']] == 'Processed') {
                        $statusClass = 'bg-info';
                        $statusText = __('admin.processed');
                    } elseif ($status[$product['status']] == 'Complete') {
                        $statusClass = 'bg-success';
                        $statusText = __('admin.complete');
                    } elseif ($product['status'] == 7) {
                        $statusClass = 'bg-warning';
                    }
                    ?>
                    <span class="badge <?= $statusClass ?>"><?= $statusText ?></span>
                </div>
            </td>
            <td class="align-middle text-center">
                <select class="form-select form-select-sm status-change-rdo" 
                        name="status_<?= $product['id'] ?>" 
                        data-id="<?= $product['id'] ?>" 
                        style="min-width: 120px;">
                    <option value=""><?= __('admin.change_status') ?></option>
                    <?php 
                        $statusOptions = $status;
                        unset($statusOptions['0']);
                        foreach ($statusOptions as $key => $value): ?>
                            <option value="<?= $key ?>"><?= $value ?></option>
                    <?php endforeach; ?>
                </select>
            </td>
            <td class="align-middle text-center">
                <div class="btn-group btn-group-sm">
                    <a href="<?= base_url('admincontrol/vieworder/'. $product['id']) ?>" 
                       class="btn btn-outline-primary" title="<?= __('admin.view_details') ?>">
                        <i class="bi bi-eye"></i>
                    </a>
                    <button class="btn btn-outline-info" onclick="showOrderDetails(<?= $product['id'] ?>)" 
                            title="<?= __('admin.quick_view') ?>">
                        <i class="bi bi-info-circle"></i>
                    </button>
                </div>
            </td>
        </tr>
    <?php endforeach; ?>
<?php else: ?>
    <tr>
        <td colspan="12" class="text-center py-5">
            <div class="d-flex justify-content-center align-items-center flex-column">
                <i class="bi bi-cart-x display-1 text-muted mb-3"></i>
                <h4 class="text-muted mb-2"><?= __('admin.no_orders_found') ?></h4>
                <p class="text-muted"><?= __('admin.no_orders_match_criteria') ?></p>
            </div>
        </td>
    </tr>
<?php endif; ?>