<?php

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

$lang = Yii::$app->language;

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

?>

<div class="update-items-variations">

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

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            $lang == 'en' ?

                [
                    'label' => Yii::t('app', 'Main Category'),
                    'attribute' => 'main_category',
                    'filter' => ArrayHelper::map($main_categories, 'id', 'english_name'),
                    'value' => function($model, $lang) {
                        if ($model->item->main_category_id) {
                            return $model->item->mainCategory->english_name;
                        }
                    }
                ]
            :
                [
                    'label' => Yii::t('app', 'Main Category'),
                    'attribute' => 'main_category',
                    'filter' => ArrayHelper::map($main_categories, 'id', 'arabic_name'),
                    'value' => function($model, $lang) {
                        if ($model->item->main_category_id) {
                            return $model->item->mainCategory->arabic_name;
                        }
                    }
                ],
            $lang == 'en' ?
                [
                    'label' => Yii::t('app', 'Sub Category'),
                    'attribute' => 'sub_category',
                    'filter' => ArrayHelper::map($sub_categories, 'id', 'english_name'),
                    'value' => function($model, $lang) {
                        if ($model->item->sub_category_id) {
                            return $model->item->subCategory->english_name;
                        }
                    }
                ]
            :
                [
                    'label' => Yii::t('app', 'Sub Category'),
                    'attribute' => 'sub_category',
                    'filter' => ArrayHelper::map($sub_categories, 'id', 'arabic_name'),
                    'value' => function($model, $lang) {
                        if ($model->item->sub_category_id) {
                            return $model->item->subCategory->arabic_name;
                        }
                    }
                ],
            [
                'label' => Yii::t('app', 'Arabic Name'),
                'attribute' => 'arabic_name',
                'value' => function($model) {
                    return $model->item->arabic_name . ' (' . $model->arabic_description . ')';
                }
            ],
            [
                'label' => Yii::t('app', 'English Name'),
                'attribute' => 'english_name',
                'value' => function($model) {
                    return $model->item->english_name . ' (' . $model->english_description . ')';
                }
            ],
            [
                // 'label' => 'Price',
                'attribute' => 'price',
                'value' => function($model) {
                    return  Editable::widget([
                        'model' => $model,
                        'attribute' => 'price',
                        'header' => Yii::t('app', 'Price'),
                        // 'asPopover' => false,
                        'size'=>'sm',
                        'inputType' => Editable::INPUT_TEXT,    
                        'value' => $model->price,
                        'options'=>[
                            'options'=> ['placeholder' => Yii::t('app', 'Price')],
                            'id' => 'var_' . $model->id
                        ],
                        'preHeader' => Yii::t('app', 'Edit') . " ",
                        'formOptions' => [
                            'action' => Url::base() . '/items/edit-price?id=' . $model->id,
                            'method' => 'get'
                        ] ,
                    ]);
                },
                'format' => 'raw'
            ],
        ],
    ]); ?>

</div>