<?php
/**
 * @var $usePagination string
 * @var $showEstimatedPriceInItemsList boolean
 * @var $displayStartPriceInCatalog boolean
 * @var $categoryList array
 * @var $isArchived bool
 * @var $isShop bool
 */

use auctionforge\inc\controllers\Settings;
use auctionforge\inc\helpers\SettingsHelper;
use auctionforge\inc\helpers\View;
use auctionforge\inc\model\Auction;

global $wp_query;

$filterByPhrase = (isset($_GET['phrase_by'])) ? $_GET['phrase_by'] : "";
$filterCategoryBy = (isset($_GET['category_by'])) ? $_GET['category_by'] : "";
$filterSortBy = (isset($_GET['sort_by'])) ? $_GET['sort_by'] : "";
$part = get_query_var('part');
$extendedSorting = SettingsHelper::isChecked(Settings::EXTENDED_SORTING_OPTION, false);
$isShop = !empty($isShop) ? $isShop : false;

$perPageDefault = get_option('posts_per_page');
$isPaginationActive = true;
?>
<div class="bp-lots bp-tools bp-col bp-d-flex bp-md-f-wrap bp-f-center">
    <form id="bp-from-tools" action="" class="bp-from bp-from__tools">
        <div class="bp-content__filter bp-from__item bp-d-flex">
            <!-- Categories -->
            <?php if (!empty($categoryList)) { ?>
                <div class="bp-form_category bp-form-tools__item bp-form-group">
                    <div class="bp-form-group">
                        <div class="bp-form-group__inner">
                            <select class="bp-form-control bp-filter-select2" name="category_by" style="width: 100%;">
                                <option selected="selected" value=""></option>
                                <?php foreach ($categoryList as $key => $value) { ?>
                                    <?php
                                    if ($key == $perPageDefault) {
                                        $key = "";
                                    }
                                    ?>
                                    <option <?= selected(($filterCategoryBy == $key)) ?> value="<?= $key ?>"><?= $value ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
            <?php } ?>
            <!-- Sorting -->
            <style>
.bp-form_sorter .select2-selection__rendered,
.bp-form_sorter .select2-results__option { font-size: 16px !important; }
</style>
<div class="bp-form_sorter bp-form_select2 bp-form-tools__item">
                <div class="bp-form-group">
                    <div class="bp-form-group__inner">
                        <?php
                        if ($isShop) {
                            // Shop (buy-it-now) auctions get simplified sort options
                            $values = array(
                                'id|desc' => 'Recently Added',
                                'buyoutPrice|desc' => 'Price: High',
                                'buyoutPrice|asc' => 'Price: Low',
                            );
                        } else {
                            $values = array(
                                'paddedIndex|asc' => 'Lot Number',
                            );
                            if (empty($isArchived)) {
                                $values['leadingBid|desc'] = 'Leading Bid: High';
                                $values['leadingBid|asc'] = 'Leading Bid: Low';
                            }
                            $values['effectivePrice|desc'] = 'Price: High';
                            $values['effectivePrice|asc'] = 'Price: Low';
                            $values['estimatedPriceInt|desc'] = 'Estimate: Highest';
                            $values['mostActive|desc'] = 'Most Active';
                        }
                        $values = apply_filters('auctionforge_sorting_values_filter', $values);
                        ?>
                        <select class="bp-form-control bp-filter-select2" name="sort_by" style="width: 100%;">
                            <?php foreach ($values as $key => $value) { ?>
                                <option <?= selected(($filterSortBy == $key)) ?> value="<?= $key ?>">
                                    <?= __($value, "auctionforge") ?>
                                </option>
                            <?php } ?>
                        </select>
                        <?php if (0 && !empty($part)) { ?>
                            <input type="hidden" name="part" value="<?= $part ?>">
                        <?php } ?>
                    </div>
                </div>
            </div>
            <?php do_action('bp_tools_start_block'); ?>

            <div class="bp-content__filter bp-from__item bp-d-flex bp-f-end">
                <div class="bp-form__search bp-form-group">
                    <div class="bp-form-group__inner">
                        <input type="text" placeholder="<?= __("Search") ?>" value="<?= $filterByPhrase ?>" name="phrase_by" class="bp-form-control">
                        <button class="bp-btn bp-btn-search"><i class="icon-search"></i></button>
                        <button class="bp-btn bp-btn-close hidden">×</button>
                    </div>
                </div>
                <?php do_action('bp_tools_end_block'); ?>
            </div>
        </div>
        <?php do_action('bp_tools_middle_block'); ?>
    </form>
</div>
