<?php
    /**
     * @var yii\web\View     $this
     * @var Product          $collection
     * @var ProductVariant[] $variants
     * @var ProductVariant   $variant
     * @var Project[]        $projects
     * @var string|null      $referer
     */
    use common\components\artboximage\ArtboxImageHelper;
    use common\models\Project;
    use common\modules\product\models\Product;
    use common\modules\product\models\ProductVariant;
    use yii\helpers\ArrayHelper;
    use yii\helpers\Html;
    use yii\helpers\Url;
    use yii\widgets\Pjax;
    
    $this->title = $collection->brand->lang->name . ' ' . $collection->lang->name;
    if(!empty( $referer )) {
        $this->params[ 'breadcrumbs' ][] = [
            'url'   => $referer,
            'label' => \Yii::t('app', 'Return back'),
        ];
    }
    $this->params[ 'breadcrumbs' ][] = $this->title;
    $groups = $variant->getProperties();
?>
<div class="section-box box-brand margin_bottom_30">
    <div class="style new_articles-wr">
        <?php
            Pjax::begin([
                'id'      => 'collection-pjax',
                'timeout' => 5000,
            ]);
        ?>
        <div class="row">
            <div class="col-xs-12 col-sm-12 articles_data-title uppercase">
                <div class="articles-title"><?= $this->title ?></div>
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                <div class="style collection-img">
                    <?php
                        echo ArtboxImageHelper::getImage($variant->getImageUrl(), 'product');
                    ?>
                </div>
                <div class="style collection-description">
                    <div class="style colect-title uppercase">
                        <?php
                            echo $variant->lang->name;
                        ?>
                    </div>
                    <table>
                        <tr>
                            <td><?php echo Yii::t('app', 'Артикул'); ?>:</td>
                            <td>
                                <?php
                                    echo $variant->sku;
                                ?>
                            </td>
                        </tr>
                        <?php
                            foreach($groups as $group) {
                                $value = '';
                                $values = ArrayHelper::getColumn($group->_options, 'lang.value', false);
                                if(!empty( $values )) {
                                    $value = implode('; ', $values);
                                }
                                ?>
                                <tr>
                                    <td>
                                        <?php echo $group->lang->name; ?>:
                                    </td>
                                    <td>
                                        <?php
                                            echo $value;
                                        ?>
                                    </td>
                                </tr>
                                <?php
                                unset( $values, $value );
                            }
                        ?>
                    </table>
                    <div class="style">
                        <?php
                            echo Html::a(\Yii::t('app', 'Запрос на просчет'), '#', [
                                'class'   => 'to_order',
                                'data-id' => $variant->product_variant_id,
                            ]);
                        ?>
                    </div>
                    
                </div>
            </div>
            <div class="col-xs-12 col-sm-8 col-md-6 col-lg-5 collection-list">
                <ul>
                    <?php
                        foreach($variants as $variant_item) {
                            if(empty( $variant_item->lang )) {
                                continue;
                            }
                            echo Html::tag('li', Html::a(Html::tag('div', ArtboxImageHelper::getImage($variant_item->getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant_item->lang->name), [
                                'collection/view',
                                'collection_id' => $collection->product_id,
                                'variant_id'    => $variant_item->product_variant_id,
                            ]), [
                                'class' => ( ( $variant_item->product_variant_id === $variant->product_variant_id ) ? 'active' : '' ),
                            ]);
                        }
                    ?>
                </ul>
            </div>
        </div>
        <?php
            Pjax::end();
        ?>
        <div class="row">
            <div class="col-xs-12 col-sm-12 collect-tabs">
                <ul class="list-tabs">
                    <li><span><?php echo \Yii::t('app', 'Технические характеристики'); ?></span></li>
                    <?php
                        if(!empty( $collection->productCertificates )) {
                            echo Html::tag('li', Html::tag('span', \Yii::t('app', 'Сертификаты')));
                        }
                    ?>
                    <?php
                        if(!empty( $collection->productSpec->lang->instruction )) {
                            echo Html::tag('li', Html::tag('span', \Yii::t('app', 'Монтаж, уборка, уход')));
                        }
                    ?>
                    <?php
                        if(!empty( $projects )) {
                            echo Html::tag('li', Html::tag('span', \Yii::t('app', 'Галерея объектов')));
                        }
                    ?>
                </ul>
                <div class="style t_content_wr">
                    <div class="tabs-content">
                        <?php
                            if(!empty( $collection->productSpec->lang->tech_spec_text )) {
                                echo $collection->productSpec->lang->tech_spec_text;
                            }
                            if(!empty( $collection->productSpec->getTechSpecUrl() )) {
                                echo Html::tag('p', \Yii::t('app', 'Документ технической документации') . ':' . Html::a(\Yii::t('app', 'скачать'), $collection->productSpec->getTechSpecUrl(), [ 'download' => true ]));
                            }
                            if(!empty( $collection->productSpec->getTechCharUrl() )) {
                                echo Html::tag('p', \Yii::t('app', 'Вы также можете скачать таблицу с ') . Html::a(\Yii::t('app', 'техническими характеристиками'), $collection->productSpec->getTechCharUrl(), [ 'download' => true ]));
                            }
                        ?>
                    </div>
                    <?php
                        if(!empty( $collection->productCertificates )) {
                            ?>
                            <div class="tabs-content">
                                <div class="row">
                                    <?php
                                        foreach($collection->productCertificates as $productCertificate) {
                                            echo Html::tag('div', Html::tag('iframe', '', [
                                                'class'       => 'certificate',
                                                'frameborder' => 0,
                                                'src'         => 'http://docs.google.com/gview?url=' . Url::to('/storage/certificates/' . $collection->product_id . '/' . $productCertificate->link, true) . '&embedded=true',
                                            ]), [ 'class' => 'col-xs-12 col-sm-6 col-md-4 col-lg-4' ]);
                                        }
                                    ?>
                                </div>
                            </div>
                            <?php
                        }
                        if(!empty( $collection->productSpec->lang->instruction )) {
                            echo Html::tag('div', $collection->productSpec->lang->instruction, [ 'class' => 'tabs-content' ]);
                        }
                        
                        if(!empty( $projects )) {
                            ?>
                            <div class="tabs-content">
                                <ul class="" style="list-style: none">
                                    <?php
                                        foreach($projects as $project) {
                                            echo Html::tag('li', Html::a(ArtboxImageHelper::getImage($project->image->getImageUrl(), 'collection_gallery'), [
                                                'project/view',
                                                'id' => $project->project_id,
                                            ]), [
                                                'class' => 'col-xs-12 col-sm-4 col-md-4 col-lg-4',
                                            ]);
                                        }
                                    ?>
                                </ul>
                            </div>
                            <?php
                        }
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>