<?php
/**
 * @version 7.10 [rev.7.10.01]
 */
/* @var \Ppb\Db\Table\Row\Listing $listing */
$link = $this->url($listing->link());

$seller = (isset($seller)) ? $seller : false;

$this->userDetails($listing->findParentRow('\Ppb\Db\Table\Users'));
$class = ((!empty($class)) ? $class : 'list') .
    (($listing['highlighted']) ? ' highlighted' : '');

$lazyLoad = (isset($lazyLoad)) ? $lazyLoad : true;
?>

<div class="<?php echo $class; ?>">
    <div class="image">
        <a href="<?php echo $link; ?>">
            <?php echo $this->thumbnail($listing->getMainImage(), 250, true,
                array('alt' => $listing['name'], 'lazyLoad' => $lazyLoad)); ?>
        </a>
    </div>
    <div class="description">
        <div class="title">
            <h3>
                <a href="<?php echo $link; ?>"><?php echo $listing['name']; ?></a>
            </h3>
            <?php if ($this->enhanced) { ?>
                <div>
                    <small>[ <?php echo $this->_('ID:') . ' ' . $listing['id']; ?> ]</small>
                </div>
            <?php } ?>
            <p><?php echo $listing['subtitle']; ?></p>
        </div>
        <div class="price">
            <?php echo $this->partial('partials/current-price.phtml', array('listing' => $listing)); ?>
        </div>
        <?php if (!$listing['draft']) { ?>
            <?php if ($listing['listing_type'] == 'auction') { ?>
                <?php if ($seller && $listing['reserve_price'] > 0) { ?>
                    <div class="reserve">
                        <abbr title="<?php echo $this->_('Reserve Price'); ?>">
                            <?php echo $this->amount($listing['reserve_price'], $listing['currency']); ?>
                        </abbr>
                    </div>
                <?php } ?>

                <div class="bids">
                    <?php echo $listing->countDependentRowset('\Ppb\Db\Table\Bids'); ?>
                    <?php echo $this->_('bids'); ?>
                </div>
            <?php } ?>

            <?php if ($seller && empty($listing['stock_levels']) && $listing['listing_type'] == 'product') { ?>
                <div class="quantity">
                    <?php echo $this->_('Quantity:'); ?>
                    <?php echo $listing['quantity']; ?>
                </div>
            <?php } ?>

            <?php if (strtotime($listing['start_time']) > time()) { ?>
                <div class="ends text-info">
                    <?php echo $this->_('Starts in'); ?>
                    <?php echo $this->countdown($listing['start_time'])->timeLeft(); ?>
                </div>
            <?php
            }
            else if ($listing['end_time']) {
                ?>
                <div class="ends">
                    <?php echo $this->countdown($listing['end_time'])->timeLeft(); ?>
                </div>
            <?php } ?>
        <?php } ?>

        <?php if (!$seller) { ?>
            <div class="owner">
                <div><?php echo $this->userDetails()->display(); ?></div>
                <div><?php echo $this->userDetails()->location(); ?></div>
            </div>
        <?php } ?>

        <?php if ($this->enhanced && !$listing['draft']) { ?>
            <div class="clearfix"></div>
            <div class="stats">
                <div>
                    <?php echo $this->_('Start Time:'); ?>
                    <?php echo $this->date($listing['start_time']); ?>
                </div>
                <div>
                    <?php echo $this->_('End Time:'); ?>
                    <?php echo $this->date($listing['end_time']); ?>
                </div>
            </div>
        <?php } ?>
    </div>

</div>