<div class="header">
    <h1>Gas kit add-ons</h1>
</div>
<p style="margin-bottom: 1rem; color: var(--text-light);">Items customers can add when ordering a new gas kit (e.g. gas cooker, hose pipe, regulator, grill, burner). Shown in the app when they select "New kit".</p>
<form method="get" action="<?= base_url('admin/gas-kit-addons') ?>" style="display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem;">
    <div>
        <label for="q">Search add-on name</label>
        <input type="text" name="q" id="q" value="<?= esc($filter_q ?? '') ?>" placeholder="Search…" style="min-width: 180px;">
    </div>
    <button type="submit" class="btn btn-primary">Search</button>
    <?php if (($filter_q ?? '') !== ''): ?>
    <a href="<?= base_url('admin/gas-kit-addons') ?>" class="btn btn-secondary">Clear</a>
    <?php endif ?>
</form>
<form method="post" action="<?= base_url('admin/gas-kit-addons/add') ?>" style="display:flex; align-items:center; gap:0.5rem; flex-wrap:wrap; margin-bottom:1.5rem;">
    <input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>">
    <input type="text" name="name" placeholder="Name (e.g. Gas cooker 2 burner)" required style="min-width:200px;">
    <input type="number" name="price" placeholder="Price (UGX)" step="0.01" min="0" style="width:120px;">
    <input type="number" name="sort_order" placeholder="Order" value="0" style="width:70px;">
    <button type="submit" class="btn btn-primary">Add</button>
</form>

<table>
    <thead>
        <tr><th>ID</th><th>Name</th><th>Price (UGX)</th><th>Order</th><th></th></tr>
    </thead>
    <tbody>
        <?php foreach ($addons as $a): ?>
        <tr>
            <td><?= (int) $a->id ?></td>
            <td><?= esc($a->name) ?></td>
            <td><?= number_format((float) $a->price) ?></td>
            <td><?= (int) $a->sort_order ?></td>
            <td>
                <a href="<?= base_url('admin/gas-kit-addons/edit/' . $a->id) ?>" class="btn btn-secondary" style="margin-right:0.5rem;">Edit</a>
                <form method="post" action="<?= base_url('admin/gas-kit-addons/delete/' . $a->id) ?>" style="display:inline;" onsubmit="return confirm('Delete this add-on?');">
                    <input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>">
                    <button type="submit" class="btn btn-secondary" style="color:var(--red, #dc2626);">Delete</button>
                </form>
            </td>
        </tr>
        <?php endforeach ?>
        <?php if (empty($addons)): ?>
        <tr><td colspan="5">No add-ons. Add items above (e.g. Gas cooker, Hose pipe, Regulator, Grill, Burner).</td></tr>
        <?php endif ?>
    </tbody>
</table>
