<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\DetailView;
use yii\bootstrap\Modal;

/* @var $this yii\web\View */
/* @var $model app\models\SubCategories */
$lang = Yii::$app->language;
$this->title = $lang == 'en' ? $model->english_name : $model->arabic_name;
$this->params['breadcrumbs'][] = ['label' => $lang == 'en' ? $model->mainCategory->english_name : $model->mainCategory->arabic_name, 'url' => ['main-categories/view?id=' . $model->main_category_id]];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="sub-categories-view">

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

    <p>
        <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
        <?php if (!$model->items) : ?>
            <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
                'method' => 'post',
            ],
        ]) ?>
        <?php endif; ?>
        <?= Html::button(Yii::t('app', 'Special Item'),
            ['value' => Url::to(['/sub-categories/special-item', 'id' => $model->id]), 'class' => 'special_item_btn btn btn-success', 'id' => 'special_item_btn']
        ) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            [
                'attribute' => 'main_category_id',
                'value' => function($model, $lang) {
                    if ($model->main_category_id) {
                        return $lang == 'en' ? $model->mainCategory->english_name : $model->mainCategory->arabic_name;
                    }
                }
            ],
            'arabic_name',
            'english_name',
            [
                'attribute' => 'status',
                'value' => function($model, $lang) {
                    if ($model->status == 'Active') {
                        return Yii::t('app', 'Active');
                    }
                    else {
                        return Yii::t('app', 'Inactive');
                    }
                }
            ],
        ],
    ]) ?>

</div>

<?php
	Modal::begin([
		'header' => '<h3>' . Yii::t('app', 'Select Special Item for this category') . '</h3>',
		'id' => 'special_item',
		'size' => 'modal-md'
    ]);

    echo '<div id="choose_special_item"></div>';

    Modal::end();
?>
