<?php
    
    use common\models\ProductToProject;
    use common\models\ProductToProjectSearch;
    use common\models\Project;
    use yii\data\ActiveDataProvider;
    use yii\helpers\Html;
    use yii\grid\GridView;
    use yii\helpers\Url;
    use yii\web\View;
    
    /**
     * @var View                   $this
     * @var ProductToProjectSearch $searchModel
     * @var ActiveDataProvider     $dataProvider
     * @var Project                $project
     */
    
    $this->title = \Yii::t('app', 'Product to project: ') . $project->lang->title;
    $this->params[ 'breadcrumbs' ][] = [
        'label' => \Yii::t('app', 'Project'),
        'url'   => [ 'index' ],
    ];
    $this->params[ 'breadcrumbs' ][] = $this->title;
?>
<div class="articles-index">
    
    <h1 itemprop="title"><?= Html::encode($this->title) ?></h1>
    
    <p>
        <?= Html::a(\Yii::t('app', 'Product to project'), [
            'product-create',
            'id' => $project->project_id,
        ], [ 'class' => 'btn btn-success' ]) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel'  => $searchModel,
        'columns'      => [
            [
                'attribute' => 'variant_name',
                'value'     => function($model) {
                    /**
                     * @var ProductToProject $model
                     */
                    return Html::a($model->productVariant->lang->name, [
                        'product/variant/view',
                        'id' => $model->productVariant->product_variant_id,
                    ]);
                },
                'format'    => 'html',
            ],
            [
                'attribute' => 'product_name',
                'value'     => function($model) {
                    /**
                     * @var ProductToProject $model
                     */
                    return Html::a($model->product->lang->name, [
                        'product/manage/view',
                        'id' => $model->product->product_id,
                    ]);
                },
                'format'    => 'html',
            ],
            [
                'class'    => 'yii\grid\ActionColumn',
                'template' => '{update} {delete}',
                'buttons'  => [
                    'update' => function($url, $model, $key) {
                        /**
                         * @var ProductToProject $model
                         */
                        return Html::a(Html::tag('span', '', [
                            'class' => 'glyphicon glyphicon-pencil',
                        ]), Url::to([
                            'project/product-update',
                            'id'                    => $model->project_id,
                            'product_to_project_id' => $model->product_to_project_id,
                        ]));
                    },
                    'delete' => function($url, $model, $key) {
                        /**
                         * @var ProductToProject $model
                         */
                        return Html::a(Html::tag('span', '', [
                            'class' => 'glyphicon glyphicon-trash',
                        ]), Url::to([
                            'project/product-delete',
                            'product_to_project_id' => $model->product_to_project_id,
                        ]), [
                            'data-confirm' => \Yii::t('app', 'Вы уверены, что хотите удалить этот элемент?'),
                            'title'        => \Yii::t('app', 'Удалить'),
                            'data-method'  => 'post',
                            'data-pjax'    => 0,
                        ]);
                    },
                ],
            ],
        ],
    ]); ?>
</div>
