<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\components\artboxtree\treelist\TreeListWidget;
use common\components\artboxtree\treegrid\TreeGridWidget;
use common\components\artboxtree\treemenu\TreeMenuWidget;

/* @var $this yii\web\View */
/* @var $searchModel common\modules\rubrication\models\TaxOptionSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('rubrication', 'Options for group "{group}"', ['group' => $group->name]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('rubrication', 'Groups'), 'url' => ['tax-group/index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="tax-option-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('rubrication', 'Create Option'), ['create?group='. $group->tax_group_id], ['class' => 'btn btn-success']) ?>
    </p>

<?php if($group->hierarchical) :?>
    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            [
                'label'=> Yii::t('rubrication', 'Value'),
                'content'=>function($data){
                    return str_repeat('-', $data->depth) .'&nbsp;'. $data->ValueRenderFlash;
                }
            ],
            'alias',
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {update} {delete} {synonim}',
                'buttons' => [
                    'synonim' => function ($url, $model) {
                        return Html::a('<span class="glyphicon glyphicon-tasks"></span>', $url, [
                            'title' => Yii::t('rubrication', 'Synonims'),
                        ]);
                    },
                ],
                'urlCreator' => function ($action, $model, $key, $index) {
                    if ($action === 'view') {
                        $url = '/admin/rubrication/tax-option/view?id=' . $model->tax_option_id;
                        return $url;
                    } elseif ($action === 'update') {
                        $url ='/admin/rubrication/tax-option/update?id='.$model->tax_option_id;
                        return $url;
                    } elseif ($action === 'delete') {
                        $url ='/admin/rubrication/tax-option/delete?id='.$model->tax_option_id;
                        return $url;
                    } elseif ($action === 'synonim') {
                        $url ='/admin/rubrication/tax-synonim/delete?id='.$model->tax_option_id;
                        return $url;
                    }
                }
            ],
        ],
    ]);?>
<?php else :?>
    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'valueRenderHTML',
            'alias',
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{update} {delete} {synonim}',
                'buttons' => [
                    'synonim' => function ($url, $model) {
                        return Html::a('<span class="glyphicon glyphicon-tasks"></span>', $url, [
                            'title' => Yii::t('rubrication', 'Synonims'),
                        ]);
                    },
                ],
                'urlCreator' => function ($action, $model, $key, $index) {
                    if ($action === 'update') {
                        $url ='/admin/rubrication/tax-option/update?id='.$model->tax_option_id;
                        return $url;
                    } elseif ($action === 'delete') {
                        $url ='/admin/rubrication/tax-option/delete?id='.$model->tax_option_id;
                        return $url;
                    } elseif ($action === 'synonim') {
                        $url ='/admin/rubrication/tax-synonim/delete?id='.$model->tax_option_id;
                        return $url;
                    }
                }
            ],
        ],
    ]);?>
<?php endif?>
</div>
