<?php
/**
 * @version 7.10 [rev.7.10.01]
 */
/** @var \Ppb\Db\Table\Row\User $user */
$this->userDetails($user); ?>
    <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-address')); ?>">
                <?php echo $this->_('Add Address'); ?>
            </a>
        </div>
    </nav>

    <div class="table-responsive">
        <table class="table">
            <caption>
                <strong><?php echo $this->paginator->getPages()->totalItemCount; ?></strong>
                <?php echo $this->_('addresses found in your address book.'); ?>

                <?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><?php echo $this->_('Address'); ?></th>
                    <th class="size-mini"></th>
                    <th class="size-small"><?php echo $this->_('Options'); ?></th>
                </tr>
                </thead>
            <?php } ?>
            <tbody>
            <?php
            /** @var \Ppb\Db\Table\Row\UserAddressBook $address */
            foreach ($this->paginator as $address) {
                ?>

                <tr <?php echo ($address->isPrimary()) ? 'class="success"' : ''; ?>>
                    <td>
                        <?php echo $this->userDetails()->setAddress($address['id'])->displayFullAddress(); ?>
                    </td>
                    <td>
                        <?php if ($address->isPrimary()) { ?>
                            <span class="label label-primary"><?php echo $this->_('Primary'); ?></span>
                            <?php
                        }
                        else {
                            ?>
                            <a class="btn btn-sm btn-default confirm-box"
                               href="<?php echo $this->url(array('action' => 'primary-address', 'id' => $address['id'])); ?>"
                               title="<?php echo $this->_('Set as Primary'); ?>"
                               data-message="<?php echo $this->_('Are you sure you want to set this address as your primary address?'); ?>">
                                <i class="fa fa-key"></i>
                            </a>
                        <?php } ?>
                    </td>
                    <td>
                        <div class="btn-group">
                            <?php if ($address->canEdit()) { ?>
                                <a class="btn btn-sm btn-default"
                                   href="<?php echo $this->url(array('action' => 'edit-address', 'id' => $address['id']), null, true); ?>"
                                   title="<?php echo $this->_('Edit Address'); ?>">
                                    <i class="fa fa-folder-open"></i>
                                </a>
                            <?php } ?>
                            <?php if ($address->canDelete()) { ?>
                                <a class="btn btn-sm btn-danger confirm-box"
                                   href="<?php echo $this->url(array('action' => 'delete-address', 'id' => $address['id']), null, true); ?>"
                                   title="<?php echo $this->_('Delete Address'); ?>"
                                   data-message="<?php echo $this->_('Are you sure you want to delete this address from the address book?'); ?>">
                                    <i class="fa fa-times"></i>
                                </a>
                            <?php } ?>
                        </div>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>

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