<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex justify-content-between align-items-center mb-3">
    <h1 class="h3 mb-0">Orders</h1>
    <a href="<?= site_url('pos/orders/new') ?>" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New Order</a>
</div>

<div class="card shadow-sm">
    <div class="table-scroll">
        <table class="table table-hover mb-0 align-middle">
            <thead class="table-light"><tr><th>#</th><th>Type</th><th>Table</th><th>Status</th><th class="text-end">Action</th></tr></thead>
            <tbody>
                <?php if (empty($orders)): ?>
                    <tr><td colspan="5" class="text-center text-muted py-4">No active orders.</td></tr>
                <?php endif; ?>
                <?php foreach ($orders as $order): ?>
                    <tr style="cursor:pointer" onclick="window.location='<?= site_url('pos/orders/' . $order->id) ?>'">
                        <td>#<?= $order->id ?></td>
                        <td><?= esc($lookups->posOrderTypes[$order->order_type]['label'] ?? $order->order_type) ?></td>
                        <td><?= esc($order->table_number ?: '—') ?></td>
                        <td><span class="badge bg-<?= esc($lookups->posOrderStatuses[$order->status]['badge'] ?? 'secondary') ?>"><?= esc($lookups->posOrderStatuses[$order->status]['label'] ?? $order->status) ?></span></td>
                        <td class="text-end"><a href="<?= site_url('pos/orders/' . $order->id) ?>" class="btn btn-sm btn-outline-primary">Open</a></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<?= $this->endSection() ?>
