<div class="modal" id="modal-search"></div>

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

    <div class="actions">
        <a data-load-with-modal data-modal="modal-search" class="btn btn-default btn-sm" href="<?= admin_url_to('/direct-market/rescues/search') ?>"><?= __('Search') ?></a>
    </div>
</section>

<section class="content">
    <?php if (!$rescues): ?>
        <div class="callout callout-warning">
            <h4>Ops!</h4>
            <p><?= __('No orders found') ?></p>
        </div>
    <?php else: ?>
        <div class="box box-default table-responsive">
            <table data-table class="table table-condensed table-hover table-striped">
                <thead>
                    <tr>
                        <th width="60">#ID</th>
                        <th><?= __('Account') ?></th>
                        <th><?= __('Total value') ?></th>
                        <th><?= __('Tax') ?></th>
                        <th><?= __('Value') ?></th>
                        <th><?= __('PIX') ?></th>
                        <th width="180"><?= __('Created at') ?></th>
                        <th width="120"><?= __('Status') ?></th>
                        <th width="10"></th>
                    </tr>
                </thead>

                <tbody>
                    <?php foreach ($rescues as $rescue): ?>
                        <tr>
                            <td><?= $rescue['id'] ?></td>
                            <td><a data-ajax href="<?= admin_url_to('/accounts/edit/' . $rescue['account']) ?>"><?= $rescue['account'] ?></a></td>
                            <td><?= util('Number')->currency($rescue['value']) ?></td>
                            <td><?= $rescue['tax'] ?>%</td>
                            <td><?= util('Number')->currency($rescue['value'] - ($rescue['value'] * ($rescue['tax'] / 100))) ?></td>
                            <td><?= $rescue['pix'] ?></td>
                            <td><?= util('Date')->dateTime($rescue['create_date']) ?></td>
                            <td><?= $rescue['status'] ?></td>
                            <td>
                                <?php if ($rescue['status'] === 'pending'): ?>
                                    <a data-ajax-action data-confirm="<?= __('You are sure?') ?>" href="<?= admin_url_to('/direct-market/rescues/' . $rescue['id'] . '/payed') ?>" class="btn btn-xs btn-default"><?= __('Payed') ?></a>
                                <?php endif ?>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>

            <div class="paginator">
                <?= $paginator->toHtml() ?>
            </div>
        </div>
    <?php endif ?>
</section>