<?php
use yii\helpers\Url;
use \yii\helpers\Html;
use \yii\helpers\ArrayHelper;
use common\modules\content\models\CoCategory;
use common\modules\content\models\CoContent;

/**
 * @var common\modules\content\models\SearchCoContent $casesSearchModel
 * @var common\modules\content\models\SearchCoContent $projectsSearchModel
 * @var yii\data\ActiveDataProvider $casesDataProvider
 * @var yii\data\ActiveDataProvider $projectsDataProvider
 */
?>
<div class="col-md-12">
    <ul class="nav nav-pills">
        <li class="active"><a href="#nav-pills-tab-1" data-toggle="tab">Кейсы</a></li>
        <li><a href="#nav-pills-tab-2" data-toggle="tab">Наши проекты</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane fade active in" id="nav-pills-tab-1">
            <h3 class="m-t-10">Кейсы</h3>
            <p>
                <?= Html::a(Yii::t('cases', 'Create case'), ['createcase'], ['class' => 'btn btn-success']) ?>
            </p>
            <?php
            echo \common\components\zii\AdminGrid::widget([
                'dataProvider' => $casesDataProvider,
                'filterModel' => $casesSearchModel,
                'columns' => [
                    // 'name',
                    //'url:url',
                    [
                        'attribute' => 'url',
                        'format' => 'raw',
                        'value' => function($data) {
                                /** @var CoContent $data */
                                return Html::a(
                                    (!is_null($data->lang)) ? $data->lang->name : $data->url,
                                    Yii::$app->params['frontUrl'].($data->url!='/'?'/':'').$data->url, ['target' => '_blank', 'title' => 'Просмотреть как страницу видит пользователь', 'data-toggle'=>"tooltip"]);
                            }
                    ],
                    [
                        'attribute' => 'category_id',
                        'filter' => false, //ArrayHelper::map(CoCategory::find()->all(), 'id', 'name'),
                        'format' => 'text',
                        'value' => function($data) {
                                return (!is_null($data->category)) ? $data->category->name : 'без категории';
                            }
                    ],
                    [
                        'class' => 'common\components\ColorActionColumn',
                        'template' => '{copy} {update} {delete}',
                        'buttons' => [
                            'copy' => function ($url, $model, $key) {
                                    return '<a href="'.Url::toRoute(['copy', 'id' => $model->id]).'">'.Html::beginTag('i', [
                                        'title' => "Копировать страницу",
                                        'data-toggle' => 'tooltip',
                                        'class' => 'fa fa-copy fa-lg'
                                    ]) . Html::endTag('i') . '</a>';
                                },
                        ],
                    ],
                ],
            ]); ?>
        </div>
        <div class="tab-pane fade" id="nav-pills-tab-2">
            <h3 class="m-t-10">Наши проекты</h3>
            <p>
                <?= Html::a(Yii::t('cases', 'Create project'), ['createproject'], ['class' => 'btn btn-success']) ?>
            </p>
            <?php
            echo \common\components\zii\AdminGrid::widget([
                'dataProvider' => $projectsDataProvider,
                'filterModel' => $projectsSearchModel,
                'columns' => [
                    // 'name',
                    //'url:url',
                    [
                        'attribute' => 'url',
                        'format' => 'raw',
                        'value' => function($data) {
                                /** @var CoContent $data */
                                return Html::a(
                                    (!is_null($data->lang)) ? $data->lang->name : $data->url,
                                    Yii::$app->params['frontUrl'].($data->url!='/'?'/':'').$data->url, ['target' => '_blank', 'title' => 'Просмотреть как страницу видит пользователь', 'data-toggle'=>"tooltip"]);
                            }
                    ],
                    [
                        'attribute' => 'category_id',
                        'filter' => false, //ArrayHelper::map(CoCategory::find()->all(), 'id', 'name'),
                        'format' => 'text',
                        'value' => function($data) {
                                return (!is_null($data->category)) ? $data->category->name : 'без категории';
                            }
                    ],
                    [
                        'class' => 'common\components\ColorActionColumn',
                        'template' => '{copy} {update} {delete}',
                        'buttons' => [
                            'copy' => function ($url, $model, $key) {
                                    return '<a href="'.Url::toRoute(['copy', 'id' => $model->id]).'">'.Html::beginTag('i', [
                                        'title' => "Копировать страницу",
                                        'data-toggle' => 'tooltip',
                                        'class' => 'fa fa-copy fa-lg'
                                    ]) . Html::endTag('i') . '</a>';
                                },
                        ],
                    ],
                ],
            ]); ?>
        </div>
    </div>
</div>