<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\Items */
$lang = Yii::$app->language;
$this->title = Yii::$app->language == 'ar' ? $model->arabic_name : $model->english_name;
$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>

    <p>
        <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
        <?= 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',
            ],
        ]) ?>
        <?= Html::a(Yii::t('app', 'Update Images'), ['update-images', 'id' => $model->id], ['class' => 'btn btn-success']) ?>
    </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;
                    }
                }
            ],
            [
                'attribute' => 'sub_category_id',
                'value' => function($model, $lang) {
                    if ($model->sub_category_id) {
                        return $lang == 'en' ? $model->subCategory->english_name : $model->subCategory->arabic_name ;
                    }
                }
            ],
            'arabic_name',
            'english_name',
            'arabic_description',
            'english_description',
            'preperation_method_ar',
            'preperation_method_en',
            'calories',
            'arabic_additional_sauces',
            'english_additional_sauces',
            'preparation_time',
            [
                'attribute' => 'status',
                'value' => function($model, $lang) {
                    if ($model->status == 'Active') {
                        return Yii::t('app', 'Active');
                    }
                    else {
                        return Yii::t('app', 'Inactive');
                    }
                }
            ],
            [
                'attribute' => 'is_new',
                'value' => function($model, $lang) {
                    if ($model->is_new == 0) {
                        return Yii::t('app', 'No');
                    }
                    else {
                        return Yii::t('app', 'No');
                    }
                }
            ],
        ],
    ]) ?>

    <h3><?= Yii::t('app', 'Variations') ?>:</h3>
    <div>
        <table class="table table-bordered table-striped">
        <tr>
            <th><?= Yii::t('app', 'Arabic Description') ?></th>
            <th><?= Yii::t('app', 'English Description') ?></th>
            <th><?= Yii::t('app', 'Arabic Details') ?></th>
            <th><?= Yii::t('app', 'English Details') ?></th>
            <th><?= Yii::t('app', 'Price') ?></th>
        </tr>
        <?php foreach ($item_variations as $index => $var) : ?>
            <tr>
                <td> <?=$var->arabic_description ?> </td>
                <td> <?=$var->english_description ?> </td>
                <td> <?=$var->arabic_details ?> </td>
                <td> <?=$var->english_details ?> </td>
                <td> <?=$var->price?></td>
            </tr>
        <?php endforeach; ?>
        </table>
    </div>

</div>
