<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\grid\GridView;
use kartik\editable\Editable;
use app\models\SubCategories;

/* @var $this yii\web\View */
/* @var $model app\models\Items */

$this->title = Yii::t('app', 'Uncategorized Items');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Items'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);

?>
<div class="items-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'tableOptions' => [
            'class' => 'table table-striped table-bordered table-responsive',
        ],
        'columns' => [
            'english_name',
            'arabic_name',
            [
                'attribute' => 'sub_category_id',
                'filter' => '',
                'value' => function($model) {
                    // return var_dump($model->mainCategory->subCategories);
                    return  Editable::widget([
                        'model' => $model,
                        'attribute' => 'sub_category_id',
                        'header' => Yii::t('app', 'Sub Category'),
                        // 'asPopover' => true,
                        'size'=>'md',
                        'inputType' => Editable::INPUT_DROPDOWN_LIST,    
                        'value' => $model->sub_category_id ? $model->subCategory->name : $model->sub_category_id,
                        'options'=>[
                            'options'=>['placeholder' => Yii::t('app', 'Sub Category')]
                        ],
                        'formOptions' => [
                            'action' => Url::base() . '/items/select-sub-category?id=' . $model->id,
                            'method' => 'get'
                        ],
                        'options' => ['class'=>'form-control', 'id' => $model->id],
                        'preHeader' => Yii::t('app', 'Edit') . " ",
                        'data' => ArrayHelper::map($model->mainCategory->subCategories, 'id', Yii::$app->language == 'en' ? 'english_name' : 'arabic_name'),
                        'displayValueConfig'=> ArrayHelper::map($model->mainCategory->subCategories, 'id', Yii::$app->language == 'en' ? 'english_name' : 'arabic_name'),
                    ]);
                },
                'format' => 'raw'
            ],
            [
                'class' => 'yii\grid\ActionColumn',
            ],
        ],
    ]); ?>

</div>