<?php
    /**
     * @var            $this yii\web\View
     * @var TaxOption  $purpose
     * @var Category[] $categories
     * @var array      $brands
     */
    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;
    
    $this->title = $purpose->lang->value;
    $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
            foreach($categories as $category) {
                ?>
                <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', $category->lang->name), [
                                'filter/index',
                                'category_id' => $category->category_id,
                                'purpose_id'  => $purpose->tax_option_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
                                        if(!empty( $brands[ $category->category_id ] )) {
                                            foreach($brands[ $category->category_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>
                                <!--если список больше 5 то выводим  блок .expand_brands-->
                                <?php
                                    if(count($brands[ $category->category_id ]) > 5) {
                                        ?>
                                        <div class="expand_brands">
                                            <p><?php echo \Yii::t('app', 'развернуть'); ?></p></div>
                                        <?php
                                    }
                                ?>
                                <!-------------------------------------------------------->
                            </div>
                        </div>
                    </div>
                </div>
                <?php
            }
        ?>
    </div>
</div>