<?php
/** @var $this \Zend\View\Renderer\PhpRenderer */

/** @var $layoutInfo \App\Entity\LayoutInfo */
$layoutInfo = $this->layoutInfo;
$layoutAcl = $layoutInfo->getAcl();

/** @var type $identity */
$identity = $this->identity();

$data_request = $layoutInfo->getRequest();

?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>AddCPM</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui">
    <meta name="theme-color" content="#FFFFFF">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="x-rim-auto-match" content="none">
    <!-- Favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" href="/favicon/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/favicon/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/favicon/manifest.json">
    <link rel="mask-icon" href="/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="theme-color" content="#ffffff">
    <!-- Styles -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-tokenfield.min.css">
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-tokenfield-rewrite.css">
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-datepicker.min.css">
    <link rel="stylesheet" type="text/css" href="/css/gird-column.css">
    <link rel="stylesheet" type="text/css" href="/css/reset-min.css">
    <link rel="stylesheet" type="text/css" href="/css/common-styles.css">
    <link rel="stylesheet" type="text/css" href="/css/styles-support-users.css">
    <link rel="stylesheet" type="text/css" href="/css/styles-flags.css">
    <link rel="stylesheet" type="text/css" href="/css/jquery.jgrowl.css">
    <link rel="stylesheet" type="text/css" href="/css/jquery.jgrowl.override.css">

    
    <!-- Scripts -->
    <!--[if lt IE 9]>
    <script src="/js/html5shiv.min.js"></script>
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
    <![endif]-->
    
    
    <script type="text/javascript" src="/js/detect.min.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.validate.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>    
    <script type="text/javascript" src="/js/iOS-scroll.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script type="text/javascript" src="/js/jquery.jgrowl.js"></script>
    <script type="text/javascript" src="/js/jquery.jgrowl.defaults.js"></script>
    <script type="text/javascript" src="/js/jquery.message.js"></script>

    <!-- custom page scripts & styles -->
    <?= $this->headLink() ?>
    <?= $this->headScript() ?>
    <?= $this->headStyle() ?>

</head>
<body>

<div class="top-panel">
    <a href="<?= $this->url('adm.index', ['lang' => $layoutInfo->getLang()]) ?>" title="<?= _t("Main") ?>" class="header-logo col sm-2"></a>
    <div class="button-menu">
        <p></p>
        <p></p>
        <p></p>
    </div>
</div>

<?php
    // Наличие подменю в шапке:
    if (in_array($data_request->getAttribute('page_group'), ['feeds'])) {
        $is_submenu = true;
        $is_single_item = false;
        $header_submenu_class = 'sub-menu';
        
        // Кол-во пунктов в основном меню:
        $main_menu_items = ['adm.supports', 'adm.users'];
        $allow_items_count = 0;
        foreach($main_menu_items as $item) {
            if($identity && $layoutAcl->isAllowed($identity->getRoleId(), $item)) {
                $allow_items_count++;
            }
        }
        
        if ($allow_items_count < 2) {
            $is_single_item = true;
            $header_submenu_class = '';
        }
        
    }
?>
    
    
<header class="l-header support m-menu_small <?= $header_submenu_class ?>">
    
    <nav class="wrapp row xs-no-row row-center">

        <?php
        $urlHome = $this->url(
            in_array($identityRole, [
                    \App\Acl\Roles::ROLE_ADMIN,
                    \App\Acl\Roles::ROLE_MANAGER]) ?
                'adm.index' :
                'home',
            ['lang' => $layoutInfo->getLang()]);
        ?>
        <a href="<?= $urlHome ?>" title="<?= _t("Main") ?>" class="header-logo col sm-2 xs-1"></a>
        
        <ul class="header-nav col order-xs-3 sm-6 xs-6">
            
            <?php if ($is_submenu && $is_single_item): ?>
            
                <?php if ($data_request->getAttribute('page_group') == 'feeds'): ?>
                    
                <?php endif; ?>
                    
            <?php else: ?>
            
                <?php if($identity && $layoutAcl->isAllowed($identity->getRoleId(), 'adm.supports')): ?>
                <li><a href="<?= $this->url('adm.index', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="text bold"><?= _t("Кабинет") ?></a></li>            
                <?php endif; ?>
                <?php if($identity && $layoutAcl->isAllowed($identity->getRoleId(), 'adm.users')): ?>
                <li><a href="<?= $this->url('adm.users', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="text bold"><?= _t("Пользователи") ?></a></li>
                <?php endif; ?>
                <?php if($identity && $layoutAcl->isAllowed($identity->getRoleId(), 'adm.supports')): ?>
                <li><a href="<?= $this->url('adm.supports', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="text bold"><?= _t("Менеджеры") ?></a></li>
                <?php endif; ?>
                <?php if($identity && $layoutAcl->isAllowed($identity->getRoleId(), 'adm.feeds')): ?>
                <li><a href="<?= $this->url('adm.feeds', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="text bold"><?= _t("Feed") ?></a></li>
                <?php endif; ?>
                
            <?php endif; ?>
        </ul>
        <?php
        /** @var \App\Entity\IdentityInterface $identity */
        if ($identity = $this->identity() ) :
            $gravatar = $this->gravatar($identity->getEmail());
            $gravatar->setDefaultImg(\Zend\View\Helper\Gravatar::DEFAULT_IDENTICON);
            $sxml = new SimpleXMLElement(substr($gravatar, 0, -1) . '/>');
            $src = $sxml['src'];
            ?>
            <!-- Вход произведен -->
            <div class="header-user col sm-3 order-xs-1 support">
                <picture>
                    <img src="/img/bg-img-logo.svg" alt="No logo">
                </picture>
                <a href="<?= $this->url('adm.index', ['lang' => $layoutInfo->getLang()]) ?>" class="annotation" title="<?= _t("Мой кабинет") ?>"><?= $identity->getEmail() ?></a>
                <ul class="droplist-block">
                    <li><a href="<?= $this->url('adm.profile', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("Настройки профиля") ?></a></li>
                    <li><a href="<?= $this->url('logout', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("Выход") ?></a></li>
                </ul>
            </div>
        <?php else : ?>
            <!-- Вход не был произведен -->
            <p class="header-register col sm-3 order-xs-4 xs-2">
                <a href="#" title="<?= _t("Вход") ?>" class="text bold login-button button-open"><?= _t("Вход") ?></a>
            </p>
        <?php endif; ?>
            
    </nav>
    
    <?php if ($is_submenu && !$is_single_item): ?>
        <div class="delimiter"></div>
        <nav class="wrapp row xs-no-row row-center submenu">
            <ul class="header-nav col order-xs-3 sm-8 xs-6">
                    
                <?php if (false && $data_request->getAttribute('page_group') == 'feeds'): ?>
                    
                <?php endif; ?>
                    
            </ul>
        </nav>
        
    <?php endif; ?>
    
</header>

<div class="l-popup">
    <?php // = $this->partial('app::popup/login', ['disableRegister' => true, 'isAdmin' => true, 'lang' => $layoutInfo->getLang()]) ?>
</div>

<main class="l-content">
<?php
    /** @var \Slim\Flash\Messages $flash */
    $flash = $layoutInfo->getFlash(); ?>

    <section class="b-content__work">
        <!-- quick fix for changed markup -->
        <?php if ($is_submenu && !$is_single_item): ?>
            <div style="height: 30px;"></div>
        <?php endif; ?>
        <div class="alert" role="alert" ></div>
        <!-- end quick fix for changed markup -->
        
        <?php if ($flash->hasMessage('error')) : ?>
            <?php foreach ($flash->getMessage('error')  as $msg ) : ?>
                <div class="alert alert-danger" role="alert">
                    <?= $msg ?>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
        <?php if ($flash->hasMessage('success')) : ?>
            <?php foreach ($flash->getMessage('success')  as $msg ) : ?>
                <div class="alert alert-success" role="alert">
                    <?= $msg ?>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
        <?php if ($flash->hasMessage('info')) : ?>
            <?php foreach ($flash->getMessage('info')  as $msg ) : ?>
                <div class="alert alert-info" role="alert">
                    <?= $msg ?>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>

        <!-- Main content   -->
        <?= $this->content ?>
        
    </section>

</main>

<footer class="l-footer">
    <div class="wrapp">
        <div class="b-footer__column row row-wrap">
            <div class="b-footer__column-note col order-xs-5 sm-2 xs-12">
                <p class="annotation"><?= _t("Помогаем избавиться от блокировщиков рекламы!") ?></p>
            </div>
            <div class="b-footer__column-item col order-xs-1 sm-2 xs-6">
                <p class="text bold"><?= _t("Информация 1") ?></p>
                <ul>
                    <li><a href="<?= $this->url('statistics', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("Общая статистика") ?></a></li>
                    <li><a href="<?= $this->url('user.cabinet', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("Ваш сайт") ?></a></li>
                </ul>
            </div>
            <div class="b-footer__column-item col order-xs-2 sm-2 xs-6">
                <p class="text bold"><?= _t("Информация 2") ?></p>
                <ul>
                    <li><a href="<?= $this->url('faq', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("FAQ") ?></a></li>
                    <li><a href="<?= $this->url('contacts', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("Поддержка") ?></a></li>
                </ul>
            </div>
            <div class="b-footer__column-item col order-xs-3 sm-2 xs-6">
                <p class="text bold"><?= _t("Информация 3") ?></p>
                <ul>
                    <li><a href="<?= $this->url('faq', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("FAQ") ?></a></li>
                    <li><a href="<?= $this->url('contacts', ['lang' => $layoutInfo->getLang()]) ?>" title="" class="annotation"><?= _t("Поддержка") ?></a></li>
                </ul>
            </div>
            <div class="b-footer__column-item col order-xs-4 sm-2 xs-6">
                <p class="text bold"><?= _t("Информация 4") ?></p>
                <ul>
                    <li><a href="mailto:demo@addcpm.com" title="" class="annotation">demo@addcpm.com</a></li>
                    <li><a href="skype:add.cpm" title="" class="annotation">add.cpm</a></li>
                </ul>
            </div>
        </div>
    </div>
</footer>

</body>
<?php
echo $this->inlineScript();
?>
</html>
