<?php
    
    use common\components\artboximage\ArtboxImageHelper;
    use common\modules\product\models\Brand;
    use common\modules\product\models\Category;
    use common\modules\rubrication\models\TaxOption;
    use yii\helpers\Html;
    
    /**
     * @var             $this yii\web\View
     * @var Category    $category
     * @var TaxOption[] $purposes
     * @var array       $brands
     * @var Brand[]     $brandsAll
     */
    
    $this->title = $category->lang->name;
    $this->params[ 'breadcrumbs' ][] = $this->title;
?>
<div class="section-box box-title-1 uppercase"><?= $this->title ?></div>
<div class="section-box box-category margin_bottom_30">
    <div class="row">
        <?php
            if(!empty( $brandsAll )) {
                ?>
                <div class="cat-list-wr col-xs-12 col-sm-4 col-md-4 col-lg-3">
                    <div class="cat-list">
                        <?php
                            echo Html::a(Html::tag('p', \Yii::t('app', 'All-list ').$category->lang->name), [
                                'filter/category-brands',
                                'category_id' => $category->category_id,
                            ], [
                                'class' => 'link-cat',
                                'style' => 'background-image: url("' . ArtboxImageHelper::getImageSrc($category->getImageUrl(), 'filter_image') . '")',
                            ]);
                        ?>
                        <div class="cat-list-brands-wr">
                            <div class="cat-list-brands">
                                <ul>
                                    <?php
                                        foreach($brandsAll as $brand) {
                                            /**
                                             * @var Brand $brand
                                             */
                                            echo Html::tag('li', Html::a($brand->lang->name, [
                                                'filter/category-brand',
                                                'category_id' => $category->category_id,
                                                'brand_id'    => $brand->brand_id,
                                            ]));
                                        }
                                    ?>
                                </ul>
                                <?php
                                    if(count($brandsAll) > 5) {
                                        ?>
                                        <div class="expand_brands">
                                            <p><?php echo \Yii::t('app', 'развернуть'); ?></p></div>
                                        <?php
                                    }
                                ?>
                                <!--если список больше 5 то выводим  блок .expand_brands-->
                                <!-------------------------------------------------------->
                            </div>
                        </div>
                    </div>
                </div>
                <?php
            }
        ?>
        <?php
            foreach($purposes as $purpose) {
                ?>
                <div class="cat-list-wr col-xs-12 col-sm-4 col-md-4 col-lg-3">
                    <div class="cat-list">
                        <?php
                            echo Html::a(Html::tag('p', $purpose->lang->value), [
                                'filter/index',
                                'category_id' => $category->category_id,
                                'purpose_id'  => $purpose->tax_option_id,
                            ], [
                                'class' => 'link-cat',
                                'style' => 'background-image: url("' . ArtboxImageHelper::getImageSrc($purpose->getImageUrl(), 'filter_image') . '")',
                            ]);
                        ?>
                        <div class="cat-list-brands-wr">
                            <div class="cat-list-brands">
                                <ul>
                                    <?php
                                        if(!empty( $brands[ $purpose->tax_option_id ] )) {
                                            foreach($brands[ $purpose->tax_option_id ] as $brand) {
                                                /**
                                                 * @var Brand $brand
                                                 */
                                                echo Html::tag('li', Html::a($brand->lang->name, [
                                                    'filter/brand',
                                                    'purpose_id'  => $purpose->tax_option_id,
                                                    'category_id' => $category->category_id,
                                                    'brand_id'    => $brand->brand_id,
                                                ]));
                                            }
                                        }
                                    ?>
                                </ul>
                                <?php
                                    if(count($brands[ $purpose->tax_option_id ]) > 5) {
                                        ?>
                                        <div class="expand_brands">
                                            <p><?php echo \Yii::t('app', 'развернуть'); ?></p></div>
                                        <?php
                                    }
                                ?>
                                <!--если список больше 5 то выводим  блок .expand_brands-->
                                <!-------------------------------------------------------->
                            </div>
                        </div>
                    </div>
                </div>
                <?php
            }
        ?>
    </div>
</div>