<?php if (!empty($coupons) || $balance > 0): ?>
    <div class="box-panel margin-top">
        <div class="box-panel-title"><?= __('Cashback') ?></div>
        <div class="box-panel-content">
            <table class="list">
                <thead>
                    <tr>
                        <th><?= __('Coupon') ?></th>
                        <th style="text-align:right"><?= __('Quantity') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($coupons as $coupon): ?>
                        <tr>
                            <td>
                                <a data-ajax href="<?= url_to('/donate/coupons/' . $coupon['coupon'] . '/orders') ?>">
                                    <?= $coupon['coupon'] ?>
                                </a>
                            </td>
                            <td style="text-align:right">
                                <?= $coupon['used'] ?> /
                                <?php if ($coupon['quantity'] && $coupon['quantity'] > 0): ?>
                                    <?= $coupon['quantity'] ?>
                                <?php else: ?>
                                    ∞
                                <?php endif ?>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>

            <p>
                <?= __('Your current balance is') ?> <?= util('Number')->currency($balance) ?>
            </p>

            <h2 class="title" style="margin-bottom:0"><?= __('Your rescues') ?></h2>
            <?php if (!empty($rescues)): ?>
                <table class="list">
                    <thead>
                        <tr>
                            <th><?= __('Value') ?></th>
                            <th><?= __('PIX') ?></th>
                            <th><?= __('Status') ?></th>
                            <th width="100"><?= __('Created at') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($rescues as $rescue): ?>
                            <tr>
                                <td><?= util('Number')->currency($rescue['value']) ?></td>
                                <td><?= $rescue['pix'] ?></td>
                                <td><?= $rescue['status'] ?></td>
                                <td><?= util('Date')->dateTime($rescue['create_date']) ?></td>
                            </tr>
                        <?php endforeach ?>
                    </tbody>
                </table>
            <?php else: ?>
                <div class="msg">
                    <?= __('No rescues found') ?>
                </div>
            <?php endif ?>

            <a data-ajax href="<?= url_to('/donate/cashback/rescue') ?>" class="btn margin-top"><?= __('Rescue') ?></a>
        </div>
    </div>
<?php endif ?>
