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

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

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

        <?php if (config('donate.allow_payment_confirmation', false)): ?>
            <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/orders/payment-confirmations') ?>"><?= __('Payment confirmations') ?></a>
        <?php endif ?>
    </div>
</section>

<section class="content">

    <?php if (!$total): ?>
        <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><?= __('Gateway') ?></th>
                        <th><?= __('Value') ?></th>
                        <th><?= __('Total') ?></th>
                        <th><?= __('Delivery') ?></th>
                        <th width="180"><?= __('Created at') ?></th>
                        <th width="120"><?= __('Status') ?></th>
                        <th width="10"></th>
                    </tr>
                </thead>

                <tbody>
                    <?php foreach ($orders as $order): ?>
                        <tr>
                            <td><?= $order['id'] ?></td>
                            <td><a data-ajax href="<?= admin_url_to('/accounts/edit/' . $order['username']) ?>"><?= $order['username'] ?></a></td>
                            <td><?= util('Donate.Gateway')->name($order['gateway']) ?></td>
                            <td><?= util('Number')->currency($order['value'], $order['currency']) ?></td>
                            <td><?= util('Number')->currency($order['total'], $order['currency']) ?></td>
                            <td><?= util('Number')->currency($order['delivery']) ?></td>
                            <td><?= util('Date')->dateTime($order['create_date']) ?></td>
                            <td><?= util('Donate.Gateway')->simplePaymentStatus($order['status']) ?></td>
                            <td style="white-space:nowrap">
                                <?php if ($order['status'] == 1): ?>
                                    <a href="<?= admin_url_to('/orders/confirm/' . $order['id']) ?>" data-ajax-action data-confirm="<?= __('Are you sure?') ?>" class="btn btn-success btn-xs"><?= __('Confirm') ?></a>
                                    <a href="<?= admin_url_to('/orders/refuse/' . $order['id']) ?>" data-ajax-action data-confirm="<?= __('Are you sure?') ?>" class="btn btn-danger btn-xs"><?= __('Refuse') ?></a>
                                <?php endif ?>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>

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