<?php

/* @var $this \yii\web\View */
/* @var $content string */

use app\widgets\Alert;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;


$items = [];
if (!Yii::$app->user->isGuest && Yii::$app->controller->id != 'site'){
    $items[] = ['label' => Yii::t('app', 'Main Categories'), 'url' => ['/main-categories/index'], 'options' => ['class' => 'nav-item main-categories']];
    $items[] = ['label' => Yii::t('app', 'Items'), 'url' => ['/items/index'], 'options' => ['class' => 'nav-item items']];
    $items[] = ['label' => Yii::t('app', 'Branches'), 'url' => ['/branches/index'], 'options' => ['class' => 'nav-item branches'] ];
    $items[] = ['label' => Yii::t('app', 'System Configurations'), 'url' => ['/system-configurations/configure-options'], 'options' => ['class' => 'nav-item system-configurations']];
    $items[] = ['label' => Yii::t('app', 'Admins'), 'url' => ['/admins/index'] ,'options' => ['class' => 'nav-item admins']];
    $items[] = ['label' => Yii::t('app', 'Show Menu'), 'url' => ['/menu/home'], 'linkOptions' => ['target'=>'_blank']];
}
    $items[] = Yii::$app->user->isGuest ?

                ['label' => Yii::t('app', 'Login'), 'url' => ['/admins/login'] ]
    
                :

                ['label' => Yii::t('app', 'Logout') . ' (' . ucfirst(Yii::$app->user->identity->username) . ')',
                    'url' => ['/admins/logout'],
                ];
    $items[] = Yii::$app->language == 'en' ?
                ['label' => 'عربي', 'url' => ['site/change-language', 'lang' => 'ar', 'current_url' => Yii::$app->request->url]]
                :
                ['label' => 'English', 'url' => ['site/change-language', 'lang' => 'en', 'current_url' => Yii::$app->request->url]];

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" dir="<?= Yii::$app->language == 'en' ? 'ltr': 'rtl' ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php $this->registerCsrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
    <link rel="stylesheet" href="<?=Url::base(true)?>/css/main.css" />
    <?php if (Yii::$app->controller->id == 'menu'){
         echo '<link rel="stylesheet" href="'.Url::base(true).'/css/user.css" />';
    }
    ?>
    
    <?php if(Yii::$app->language == 'ar'){
        echo '<link rel="stylesheet" href="'.Url::base(true).'/css/bootstrap-ar.min.css" />';
        echo '<link rel="stylesheet" href="'.Url::base(true).'/css/main-ar.css" />';
        if (Yii::$app->controller->id == 'menu'){
            echo '<link rel="stylesheet" href="'.Url::base(true).'/css/user-ar.css" />';
        }
        
    }?>
</head>
<body>

<?php $this->beginBody() ?>

<div class="wrap">
    
<?php
    if (Yii::$app->controller->id != 'menu') {
        NavBar::begin([
            'brandLabel' => Yii::t('app','Home Page' ),
            'brandUrl' => ['site/index'],
            'options' => [
                'class' => 'navbar-inverse special-navbar navbar-fixed-top',
            ],
        ]);
        echo Nav::widget([
            'options' => ['class' => 'navbar-nav navbar-right'],
            'items' =>  $items ,
        ]);
        NavBar::end();
    }
    
    ?>

<?php
        // NavBar::begin([
        //     'brandLabel' => "Home Page",
        //     'brandUrl' => Yii::$app->homeUrl,
        //     'options' => [
        //         'class' => 'navbar-fixed-top custom-nav container',
        //     ],
        // ]);
        // echo Nav::widget([
        //     'options' => ['class' => Yii::$app->language == 'en' ? 'navbar-nav navbar-right' : 'navbar-nav'],
        //     'items' => Yii::$app->language == 'en' ? $items : array_reverse($items),
        // ]);
        // NavBar::end();
        ?>
    <?php if (Yii::$app->controller->id == 'menu'):?>
            <?= $this->render('_top',[
                'categories' => $categories,
                'phone' => $phone,
                'restaurant_image'=>$restaurant_image,
                'logo'=> $logo
            ]) ?> 
        <?php endif; ?>
    <div class="container <?= Yii::$app->controller->id == 'menu' ? 'content': '' ?>" >
        
        <?= Breadcrumbs::widget([
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
            'homeLink' => [
                'label' => Yii::t('app', 'Home'),
                'url' => ['site/index']
            ]
        ]) ?>
        <?= Alert::widget() ?>
        
        <?= $content ?>

    </div>
</div>
<?php if (Yii::$app->controller->id != 'menu'):?>
<footer class="footer">
    <div class="container">
        <div class="row">
            <div class="col-xs-6">
            <p class="text-footer"> <?= Yii::t('app', 'Copyright') ?> &copy; <?= date("Y") ?> <?= Yii::t('app', 'Flex Solutions') ?>. <?= Yii::t('app', 'All rights reserved') ?></p>
            </div>
            <div class="col-xs-6 custom-footer">
                 <p class="text-footer"><?= Yii::t('app', 'Developed By:') ?> &nbsp;</p>
                 <a target="_blank" href="https://www.flexsolution.biz/"><?= Yii::t('app', 'Flex Solutions') ?></a>
            </div>
        </div>
       
    </div>

</footer>
<?php else:?>
    <footer class="footer footer-user">
    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                 <p class="text-footer">Developed By: Flex Solutions</p>
            </div>
        </div>
    </div>

</footer>
<?php endif;?>

<?php $this->endBody() ?>
<script>
    $(document).ready(function(){
        $('.special_item_btn').click(function(){
            $('#special_item').modal('show')
                .find('#choose_special_item')
                .load($(this).attr('value'));
        });
        $('.nav-item').removeClass('active');
        if( window.location.href.includes('-categories')){
            $('.main-categories').addClass('active');
        }
        else if(window.location.href.includes('items')){
            $('.items').addClass('active');
        }
        else if(window.location.href.includes('system-configurations')){
            $('.system-configurations').addClass('active');
        }
        else if(window.location.href.includes('admins')){
            $('.admins').addClass('active');
        }
        else if(window.location.href.includes('branches')){
            $('.branches').addClass('active');
        }
    });
</script>
</body>
</html>
<?php $this->endPage() ?>
