<?php
/**
 * @version 7.10 [rev.7.10.01]
 */
?>
<nav class="navbar navbar-filter">
    <div class="navbar-left">

        <a class="btn btn-default pull-left spacing-right"
           href="<?php echo $this->url(array('action' => 'add-voucher')); ?>">
            <?php echo $this->_('Create Voucher'); ?>
        </a>

    </div>

    <form class="navbar-form navbar-right"
          action="<?php echo $this->url(null, null, true, array('code', 'submit')); ?>"
          method="get">
        <div class="form-group">
            <?php echo $this->formElement('text', 'code', $this->code)
                ->setAttributes(array('placeholder' => $this->_('Voucher Code'), 'class' => 'form-control input-default'))
                ->render();
            ?>
        </div>
        <?php echo $this->formElement('submit', 'submit', 'Search')
            ->setAttributes(array('class' => 'btn btn-default'))
            ->render();
        ?>
    </form>
</nav>
<div class="table-responsive">
    <table class="table table-striped table-hover">
        <caption>
            <strong><?php echo $this->paginator->getPages()->totalItemCount; ?></strong> <?php echo $this->_('vouchers found.'); ?>

            <?php if ($this->paginator->getPages()->totalItemCount) { ?>
                <?php echo $this->_('Showing results'); ?>
                <strong><?php echo $this->paginator->getPages()->firstItemNumber; ?></strong>
                <?php echo $this->_('to'); ?>
                <strong><?php echo $this->paginator->getPages()->lastItemNumber; ?></strong>
            <?php } ?>
        </caption>
        <?php if ($this->paginator->getPages()->totalItemCount) { ?>
            <thead>
            <tr>
                <th class="size-small"><?php echo $this->_('Name'); ?></th>
                <th class="size-small"><?php echo $this->_('Code'); ?></th>
                <th><?php echo $this->_('Details'); ?></th>
                <th class="size-mini"><?php echo $this->_('Options'); ?></th>
            </tr>
            </thead>
        <?php } ?>
        <tbody>
        <?php
        /** @var \Ppb\Db\Table\Row\Voucher $voucher */
        foreach ($this->paginator as $voucher) {
            ?>
            <tr>
                <td>
                    <?php echo $voucher['name']; ?>
                </td>
                <td>
                    <?php echo $voucher['code']; ?>
                </td>
                <td>
                    <div>
                        <?php echo $this->_('Reduction:'); ?>
                        <?php echo ($voucher['reduction_type'] == 'percent') ?
                            \Cube\Locale\Format::getInstance()->numericToLocalized($voucher['reduction_amount']) . '%' :
                            $this->amount($voucher['reduction_amount']); ?>
                    </div>
                    <?php if ($voucher['expiration_date']) { ?>
                        <div>
                            <?php echo $this->_('Expires:'); ?> <?php echo $this->date($voucher['expiration_date']); ?>
                        </div>
                    <?php } ?>
                    <?php if ($voucher['uses_remaining'] !== null) { ?>
                        <div>
                            <?php echo $this->_('Uses Remaining:'); ?> <?php echo $voucher['uses_remaining']; ?>
                        </div>
                    <?php } ?>
                    <?php if ($voucher['assigned_listings'] != null) { ?>
                        <div>
                            <?php echo $this->_('Assigned to Listings:'); ?> <?php echo $voucher['assigned_listings']; ?>
                        </div>
                    <?php } ?>
                </td>
                <td>
                    <div class="btn-group">
                        <a class="btn btn-default btn-sm"
                           href="<?php echo $this->url(array('action' => 'edit-voucher', 'id' => $voucher['id']), null, true); ?>"
                           title="<?php echo $this->_('Edit Voucher'); ?>">
                            <i class="fa fa-folder-open"></i>
                        </a>
                        <a class="btn btn-danger btn-sm confirm-box"
                           href="<?php echo $this->url(array('action' => 'delete-voucher', 'id' => $voucher['id']),
                               null, true); ?>"
                           title="<?php echo $this->_('Delete Voucher'); ?>"
                           data-message="<?php echo $this->_('Are you sure you want to delete this voucher?'); ?>">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>

<?php echo $this->pagination($this->paginator, 'sliding', 'partials/pagination.phtml'); ?>