<?php include __DIR__ . '/../header.php'; ?>

<div class="content-wrapper">
<section class="content pt-3">
<div class="container-fluid pb-5">

    <h3 class="mb-1 fw-bold"><i class="bi bi-box-seam me-2 text-primary"></i><?= __('theme.active_product', 'Active Product') ?></h3>

    <p class="text-muted mb-4">
        <?= __('theme.choose_product', 'Choose which product will be displayed on the Landing Page.') ?>
    </p>

    <div class="card border-0 shadow-sm"><div class="card-body p-0"><div class="table-responsive">
        <table class="table table-hover align-middle mb-0">
            <thead>
            <tr>
                <th><?= __('products.id', 'ID') ?></th>
                <th><?= __('products.title', 'Title') ?></th>
                <th><?= __('products.price', 'Price') ?></th>
                <th><?= __('products.status', 'Status') ?></th>
                <th><?= __('theme.actions', 'Actions') ?></th>
            </tr>
            </thead>

            <tbody>
            <?php foreach ($products as $p): ?>
                <tr>
                    <td><?= (int)$p['id'] ?></td>
                    <td><?= htmlspecialchars($p['title']) ?></td>
                    <td><?= htmlspecialchars($p['price']) ?> <?= htmlspecialchars($p['currency'] ?? '') ?></td>
                    <td><?= htmlspecialchars($p['status']) ?></td>
                    <td>
                        <?php if ((int)$current === (int)$p['id']): ?>
                            <span class="badge bg-success">
                                <?= __('theme.current_product', 'Current Product') ?>
                            </span>
                        <?php else: ?>
                            <form method="post" action="/admin/theme/active-product/set/<?= (int)$p['id'] ?>" style="display:inline">
                                <?= \Core\System\Csrf::field() ?>
                                <button type="submit" class="btn btn-primary btn-sm">
                                    <?= __('theme.set_product', 'Set as Active Product') ?>
                                </button>
                            </form>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>

        </table>
    </div>

</div>

<?php ?>
</div></div></div></div></section></div>
<?php include __DIR__ . '/../footer.php'; ?>
