<?php
/**
 * @version 7.4
 */
/* @var int $parentId */
/* @var int $itemsPerPage */
/* @var int|null $storeId */
$storeId = (isset($storeId)) ? $storeId : null;
?>
<!-- start - container -->
<div id="browse">
    <div class="row row-offcanvas row-offcanvas-left">
        <!-- start - side bar -->
        <aside class="col-md-3 col-xs-12 sidebar-offcanvas">
            <div class="filter-results"><?php echo $this->_('Filter Results'); ?></div>
            <?php echo $this->basicSearchForm; ?>
        </aside>
        <!-- end - side bar -->

        <!-- start - content -->
        <section class="col-md-9 col-xs-12">
            <div class="row browse-title">
                <div class="col-xs-2 col-sm-1 hidden-md hidden-lg">
                    <button class="btn btn-default" data-toggle="offcanvas" type="button">
                        <i class="fa fa-2x fa-list"></i>
                    </button>
                </div>
                <div class="col-xs-10 col-sm-11 col-md-12">
                    <?php if ($storeId) { ?>
                        <h2 class="section-title"><?php echo $browsePageTitle; ?></h2>
                    <?php
                    }
                    else {
                        ?>
                        <h1 class="section-title"><?php echo $browsePageTitle; ?></h1>
                    <?php } ?>
                </div>
            </div>
            <div class="clearfix"></div>

            <?php if ($parentId) { ?>
                <?php $featuredItemsContent = $this->action('listings', 'browse', 'listings', array('type' => 'categories', 'parent_id' => $parentId, 'limit' => 4)); ?>
                <?php if (!empty($featuredItemsContent)) { ?>
                    <!-- start - category featured listings -->
                    <div class="featured">
                        <h2><?php echo $this->_('Featured Items'); ?></h2>
                        <?php echo $featuredItemsContent; ?>
                    </div>
                    <!-- end - category featured listings -->
                <?php } ?>
            <?php } ?>

            <?php if ($this->paginator->getPages()->totalItemCount) { ?>
                <!-- start - ordering/display options -->
                <div class="row">
                    <div class="view-switch col-sm-2 col-xs-12">
                        <a href="#" id="list"
                           title="<?php echo $this->_('List View'); ?>"><?php echo $this->_('List view'); ?></a>
                        <a href="#" id="grid"
                           title="<?php echo $this->_('Grid View'); ?>"><?php echo $this->_('Grid view'); ?></a>
                    </div>
                    <div class="col-sm-6 col-xs-12">
                        <strong><?php echo $this->paginator->getPages()->totalItemCount; ?></strong> <?php echo $this->_('listings 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 } ?>
                    </div>
                    <div class="col-sm-4 col-xs-12">
                        <?php
                        $sortOptions = array(
                            'relevance'    => $this->_('Relevance'),
                            'price_asc'    => $this->_('Price Low to High'),
                            'price_desc'   => $this->_('Price High to Low'),
                            'started_desc' => $this->_('Recently Listed'),
                            'ending_asc'   => $this->_('Ending Soon')
                        );
                        $sort = (isset($params['sort'])) ? $params['sort'] : 'relevance';
                        ?>
                        <div class="btn-group pull-right">
                            <button
                                class="btn btn-default"><?php echo (array_key_exists($sort, $sortOptions)) ? $sortOptions[$sort] : $this->_('Sort By'); ?></button>
                            <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>

                            <ul class="dropdown-menu text-left">
                                <?php foreach ($sortOptions as $key => $value) { ?>
                                    <li>
                                        <a href="<?php echo $this->url(array('sort' => $key), null, true); ?>"><?php echo $value; ?></a>
                                    </li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- end - ordering/display options -->

                <div class="clearfix"></div>

                <!-- start - listings display -->
                <div class="listings">
                    <?php
                    /** @var \Ppb\Db\Table\Row\Listing $listing */
                    foreach ($this->paginator as $listing) {
                        echo $this->partial('partials/listing-box.phtml', array(
                            'listing' => $listing));
                    } ?>
                </div>
                <!-- end - listings display -->

                <div class="clearfix"></div>
            <?php } ?>

            <!-- start - paginate -->
            <div>
                <?php if (!$this->paginator->getPages()->totalItemCount) { ?>
                    <div class="no-results">
                        <?php echo $this->_('There are no listings matching your query.'); ?>
                    </div>
                <?php
                }
                else {
                    ?>
                    <div class="pull-left">
                        <?php echo $this->partial('partials/items-per-page.phtml', array('itemsPerPage' => $itemsPerPage)); ?>
                    </div>
                <?php } ?>
                <div class="pull-right">
                    <?php echo $this->pagination($this->paginator, 'sliding', 'partials/pagination.phtml'); ?>
                </div>
            </div>
            <!-- end - paginate -->
        </section>
        <!-- end - content -->
    </div>

</div>
<!-- end - container -->
