<section class="content-header">
    <h1><?= __('Coupons') ?></h1>

    <div class="actions">
        <a data-ajax class="btn btn-success btn-sm" href="<?= admin_url_to('/donate/coupons/add') ?>"><?= __('Add') ?></a>
    </div>
</section>

<section class="content">
    <?php if (empty($coupons)): ?>
        <div class="callout callout-warning">
            <h4>Ops!</h4>
            <p><?= __('No coupons found') ?></p>
        </div>
    <?php else: ?>
        <div class="box box-default table-responsive">
            <table id="shops-table" class="table table-condensed table-hover table-striped">
                <thead>
                    <tr>
                        <th><?= __('Coupon') ?></th>
                        <th><?= __('Start date') ?></th>
                        <th><?= __('Expire date') ?></th>
                        <th><?= __('Discount') ?></th>
                        <th><?= __('Owner') ?></th>
                        <th><?= __('Cashback') ?></th>
                        <th><?= __('Used') ?></th>
                        <th width="80"></th>
                    </tr>
                </thead>

                <tbody>
                    <?php foreach ($coupons as $coupon): ?>
                        <tr class="<?= $coupon['active'] ? 'border-success' : 'border-error' ?>">
                            <td><?= $coupon['coupon'] ?></td>
                            <td><?= util('Date')->date($coupon['start_date']) ?></td>
                            <td><?= util('Date')->date($coupon['expire_date']) ?></td>
                            <td><?= $coupon['discount'] ?>%</td>
                            <td><?= $coupon['owner'] ?></td>
                            <td>
                                <?php if ($coupon['cashback'] && $coupon['cashback'] > 0): ?>
                                    <?= $coupon['cashback'] ?>%
                                <?php endif ?>
                            </td>
                            <td>
                                <?= $coupon['used'] ?> /
                                <?php if ($coupon['quantity'] && $coupon['quantity'] > 0): ?>
                                    <?= $coupon['quantity'] ?>
                                <?php else: ?>
                                    ∞
                                <?php endif ?>
                            </td>
                            <td class="record-actions">
                                <a data-ajax class="btn btn-xs btn-default" href="<?= admin_url_to('/donate/coupons/edit/' . $coupon['id']) ?>"><?= __('Edit') ?></a>
                                <a data-ajax-delete class="btn btn-danger btn-xs" href="<?= admin_url_to('/donate/coupons/delete/' . $coupon['id']) ?>"><?= __('Delete') ?></a>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>
        </div>
    <?php endif ?>
</section>
