<?php
/** @var $this \yii\web\View */
/** @var $productProvider \yii\data\ActiveDataProvider */
/** @var $brandProvider \yii\data\ActiveDataProvider */


use yii\helpers\Url;
use common\modules\product\helpers\ProductHelper;

$page_data = [
    'keywords' => implode(' ', $keywords),
];

if (!empty($category)) {
    $page_data['category'] = $category->name;
}

$this->title =  Yii::t('product', "Search for \"{keywords}\"". (empty($category) ? '' : ' in category \"{category}\"'), $page_data);

$this->params['seo']['seo_text'] = 'TEST SEO TEXT';
$this->params['seo']['h1'] = 'TEST H1';
$this->params['seo']['description'] = 'TEST DESCRIPTION';
$this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD';
$this->params['seo']['key']= 'product_list';
?>
<div class="w_960">
    <?php if(!empty($categories)) :?>
    <!-- side bar with all filters -->
    <div class="cat_p_filter_bar">
        <div class="title">Категории</div>
        <div class="filter_list">
            <ul>
            <?php foreach ($categories as $_category) :?>
                <li><a href="<?= Url::to(['catalog/category', 'category' => $_category, 'word' => implode(' ', $keywords)])?>"><?= $_category->name?></a></li>
            <?php endforeach?>
            </ul>
        </div>
    </div>
    <?php endif?>

    <!-- catalog list with all item cards -->
    <div class="cat_p_catalog_list">
        <div class="title"><?= Yii::t('product', "Search for \"{keywords}\"". (empty($category) ? '' : ' in category "{category}"'), $page_data)?><span><?= $productProvider->totalCount ? ' ('.$productProvider->totalCount .')' : ''?></span></div>
        <?php if (!$productProvider->count) :?>
            <h2>По данному запросу товары не найдены.</h2><br>
            <?php if (!empty($category)) :?>
            <p>Показать <a href="<?= Url::to(['catalog/category', 'category' => $category])?>">все товары из категории "<?= $category->name?>"</a></p>
            <?php endif?>
        <?php else :?>
            <!-- sort menu -->
            <div class="sort_menu">

                <div class="sort_price">
                    <span>Сортировка:</span>
                    <?= \yii\widgets\LinkSorter::widget([
                        'sort' => $productProvider->sort,
                        'attributes' => [
                            'name',
                            'price',
                        ]
                    ]);
                    ?>
                </div>

                <div class="show">
                    <!--<span>Показывать по:</span>
                    <ul>
                        <li><a class="active" href="#">24</a></li>
                        <li><a href="#">48</a></li>
                        <li><a href="#">96</a></li>
                    </ul>-->
                </div>

                <?php if ($productProvider->totalCount > $productProvider->pagination->pageSize) :?>
                <div class="show_pages">
                    Страница:
                    <?= \yii\widgets\LinkPager::widget([
                        'pagination' => $productProvider->pagination,
                        'options' => ['class' => 'pagination pull-right'],
                    ]);
                    ?>
                </div>
                <?php endif?>

            </div>

            <div class="cat_p_item_card_list">
                <div class="novelty">
                    <div class="content">
                        <div class="novelty_cont">
                            <?php foreach($productProvider->models as $product) :?>
                                <?php require(__DIR__ .'/product_item.php')?>
                            <?php endforeach?>
                        </div>

                        <?php if ($productProvider->totalCount > $productProvider->pagination->pageSize) :?>
                            <!-- LOAD MORE BUTTON -->
                            <!--button class="load_more_btn">Загрузить еще <?= $productProvider->pagination->pageSize?> товара</button-->

                            <div class="show_pages">
                                Страница:
                                <?= \yii\widgets\LinkPager::widget([
                                    'pagination' => $productProvider->pagination,
                                    'options' => ['class' => 'pagination pull-right'],
                                ]);
                                ?>
                            </div>
                        <?php endif ?>
                        <hr>

                        <?php if(!empty($category->description)) :?>
                            <div class="description">
                                <?= $category->description?>

                                <div class="empty_padding_400"></div>
                            </div>
                        <?php endif?>
                    </div>
                </div>
            </div>

        <?php endif?>
    </div>

    <?php if(!empty($last_products)) :?>
        <hr>
        <div class="watched_block">
            <h1>Вы недавно просматривали</h1>
            <div class="flex-container">
                <?php foreach($last_products as $product) :?>
                    <?php require(__DIR__ .'/product_smart.php')?>
                <?php endforeach?>
            </div>
        </div>
    <?php endif?>
</div>