<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\Breadcrumbs;

$lang = Yii::$app->language;
$this->title = 'QFood';



$script =<<< JS

var lang = $('html').attr('lang');

if(lang == 'en'){
    $('.special-tap').addClass('special-en');
    $('.new-tap').addClass('new-en');
}
else{
    $('.special-tap').addClass('special-ar');
    $('.new-tap').addClass('new-ar');
}
   
    
JS;

$this->registerJs($script);
?>

<?= $this->render('_top', $info) ?> 

<?php
    // if ($info['items'])
    // {
    if ($info['sub_category']) {
        if ($lang == 'en') {
            $this->title = $info['sub_category']->english_name;
        }
        else {
            $this->title = $info['sub_category']->arabic_name;
        }
    }
    else {
        if ($lang == 'en') {
            $this->title = $info['main_category']->english_name;
        }
        else {
            $this->title = $info['main_category']->arabic_name;
        }
    }

    $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Main Menu'), 'url' => 'categories'];
    $info['sub_category'] ? $this->params['breadcrumbs'][] = ['label' => $lang == 'en' ? $info['main_category']->english_name : $info['main_category']->arabic_name, 'url' => ['menu/sub-categories?cate_id=' . $info['main_category']->id]] : '';
    $this->params['breadcrumbs'][] = $this->title;
    // }
?>
<?= Breadcrumbs::widget([
                'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
                'homeLink' => false,
            ]) ?>

<div class="content-sub-category">
    <?php if ($info['special_item']) : ?>
        <?php $item_vars = $info['special_item']->itemVariations; ?>
        <div class="col-xs-10 col-xs-offset-1">
                <div class="sub-category-special">
                 <a  href="<?= 'item?id=' . $info['special_item']->id ?>">
                    <img class="img-sub-category-special img-responsive" src="<?= Url::base() . '/' . $info['special_item']->itemFirstImage->image_path ?>">
                    <div class="special-tap">
                        <p><?= Yii::t('app' , 'Special Item')?></p>    
                        <p><?= $lang == 'en' ? $info['special_item']->english_name : $info['special_item']->arabic_name ?></p>
                    </div>
                </a>
                </div>
           
        </div>
    <?php endif; ?>

    <?php if ($info['items'] != null) : ?>
    
    <?php foreach ($info['items'] as $index => $item) : ?>
    
        <?php $item_vars = $item->itemVariations; ?>

        <div class="col-sm-5 col-sm-offset-<?= ($index % 2 == 0 ? '1' : '0') ?> col-xs-10 col-xs-offset-1">
            <div class="sub-category">
                <a class="anchor-sub-category" href="<?= 'item?id=' . $item->id?>">
                <img class="img-sub-category img-responsive" src="<?= Url::base()?>/<?= $item->itemFirstImage->image_path ?>">
                  <div class="details">
                    <div class="title-items">
                        <p class="title-sub-category"><?= $lang == 'ar' ? $item->arabic_name : $item->english_name ?></p>
                        <p class="details-sub-category"><?= $lang == 'ar' ? $item->arabic_description : $item->english_description ?></p>
                    </div>
                    <div class="price-items">
                        <p class=" price-sub-category"><?= $item_vars[0]->price ?></p>
                        <p class="currency"><?= $info['currency'] ?></p>
                    </div>
                  </div>
                 
                <?php if ($item->is_new) : ?>
                    <div class="new-tap">
                        <p><?= Yii::t('app' , 'New')?></p>    
                    </div>
                   
                <?php endif; ?>
                <p class="text-details"><?=Yii::t('app', 'Details')?></p>
                </a>
            </div>
        </div>
    <?php endforeach; ?>
    <?php else : ?>
        <div class="col-sm-12 title-bold">
            <div class="centered center-category">
                <?= Yii::t('app', 'There are no items yet in this category!') ?>
            </div>
        </div>
    <?php endif;?>
</div>