<script type="text/javascript">
    $(function () {
        $("#bank-accounts-table").find("tbody").sortable({
            opacity: 0.6,
            cursor: "move",
            placeholder: "placeholder",
            helper: fixHelper,
            axis: "y",
            update: function() {
                var order = $(this).sortable("serialize");
                    $.post(prefix + "donate/bank-accounts/reorder", order, function(data) {
                });
            }
        });
    });
</script>

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

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

<section class="content">
    <?php if (empty($accounts)): ?>
        <div class="callout callout-warning">
            <h4>Ops!</h4>
            <p><?= __('No bank accounts found') ?></p>
        </div>
    <?php else: ?>
        <div class="box box-default table-responsive">
            <table id="bank-accounts-table" class="table table-condensed table-hover table-striped">
                <thead>
                <tr>
                    <th width="10"></th>
                    <th><?= __('Name') ?></th>
                    <th><?= __('Account') ?></th>
                    <th><?= __('Agency') ?></th>
                    <th width="80"></th>
                </tr>
                </thead>

                <tbody>
                <?php foreach ($accounts as $account): ?>
                    <tr id="sequence_<?= $account['id'] ?>">
                        <td class="record-actions">
                            <i class="fa fa-bars"></i>

                            <?php if ($account['logo']): ?>
                                <img height="50" src="<?= upload_to('/bank-accounts/' . $account['logo']) ?>" />
                            <?php endif ?>
                        </td>
                        <td><?= $account['name'] ?></td>
                        <td><?= $account['account'] ?></td>
                        <td><?= $account['agency'] ?></td>
                        <td class="record-actions">
                            <a data-ajax class="btn btn-xs btn-default" href="<?= admin_url_to('/donate/bank-accounts/edit/' . $account['id']) ?>"><?= __('Edit') ?></a>
                            <a data-ajax-delete class="btn btn-danger btn-xs" href="<?= admin_url_to('/donate/bank-accounts/delete/' . $account['id']) ?>"><?= __('Delete') ?></a>
                        </td>
                    </tr>
                <?php endforeach ?>
                </tbody>
            </table>
        </div>
    <?php endif ?>
</section>
