<?php
/**
 * @version 7.6
 */
?>

<?php echo $this->partial('partials/listing-box.phtml', array(
    'listing' => $listing, 'enhanced' => false));
?>

<div class="table-responsive">
    <table class="table table-striped table-hover">
        <caption>
            <strong><?php echo $this->paginator->getPages()->totalItemCount; ?></strong> <?php echo $this->_('offers 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><?php echo $this->_('Offer Details'); ?></th>
                <th class="size-small"><?php echo $this->_('From'); ?></th>
                <th class="size-small"><?php echo $this->_('Type / Status'); ?></th>
                <th class="size-tiny"></th>
            </tr>
            </thead>
        <?php } ?>
        <tbody>
        <?php
        /** @var \Ppb\Db\Table\Row\Offer $offer */
        foreach ($this->paginator as $offer) {
            ?>
            <tr>
                <td>

                    <?php if ($offer['type'] == 'offer') { ?>
                        <p class="price-offer">
                            <?php echo $this->amount($offer['amount'], $listing['currency']); ?>
                            <small>/ <?php echo $this->_('item'); ?></small>
                        </p>
                    <?php } ?>
                    <?php if (!empty($offer['product_attributes'])) { ?>
                        <div>
                            <small><?php echo $this->productAttributes($offer->getData('product_attributes'))->display(); ?></small>
                        </div>
                    <?php } ?>
                    <p>
                        <small><?php echo $this->_('Quantity'); ?>: <?php echo $offer['quantity']; ?></small>
                    </p>
                </td>
                <td>
                    <?php echo $this->userDetails($offer['user_id'])->display(); ?>
                </td>
                <td>
                    <?php echo $this->offerStatus($offer, true); ?>
                    <small><?php echo $this->date($offer['created_at']); ?></small>
                </td>
                <td>
                    <div class="btn-group-vertical">
                        <?php if ($offer->canAccept($listing)) { ?>
                            <a class="btn btn-sm btn-success confirm-box"
                               href="<?php echo $this->url(array('action' => 'accept', 'id' => $offer['id']),
                                   null,
                                   true); ?>"
                               title="<?php echo $this->_('Accept Offer'); ?>"
                               data-message="<?php echo $this->_('Are you sure you want to accept this offer?'); ?>">
                                <i class="fa fa-check"></i>
                            </a>
                        <?php } ?>
                        <?php if ($offer->canCounter($listing)) { ?>
                            <a class="btn btn-sm btn-counter confirm-box"
                               href="<?php echo $this->url(array('action' => 'counter', 'id' => $offer['id']),
                                   null,
                                   true); ?>"
                               title="<?php echo $this->_('Counteroffer'); ?>"
                               data-message="<?php echo $this->_('Are you sure you want to make a counteroffer?'); ?>">
                                <i class="fa fa-arrows-h"></i>
                            </a>
                        <?php } ?>
                        <?php if ($offer->canDecline()) { ?>
                            <a class="btn btn-sm btn-danger confirm-box"
                               href="<?php echo $this->url(array('action' => 'decline', 'id' => $offer['id']), null,
                                   true); ?>"
                               title="<?php echo $this->_('Decline Offer'); ?>"
                               data-message="<?php echo $this->_('Are you sure you want to decline this offer?'); ?>">
                                <i class="fa fa-ban"></i>
                            </a>
                        <?php } ?>
                        <?php if ($offer->canWithdraw()) { ?>
                            <a class="btn btn-sm btn-warning confirm-box"
                               href="<?php echo $this->url(array('action' => 'withdraw', 'id' => $offer['id']), null,
                                   true); ?>"
                               title="<?php echo $this->_('Withdraw Offer'); ?>"
                               data-message="<?php echo $this->_('Are you sure you want to withdraw this offer?'); ?>">
                                <i class="fa fa-times"></i>
                            </a>
                        <?php } ?>
                    </div>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>
