<?php
$this->ciext->load_bootstrap();
$ciext_assets_dir = '/' . $this->config->item('assets_folder') . '/' . $this->config->item('components_folder') . '/ciext';

$this->js_css->add_css($ciext_assets_dir . '/css/reset.css');

$this->js_css->parse_css('ciext/css/main.css');
$this->js_css->parse_js('ciext/js/menu.js');
$this->js_css->add_js('https://use.fontawesome.com/c1eaa95f2e.js');

// Hack
if (empty($menu)) {
    $menu = $this->admin_menu_model->get_menu_items();
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>{title}</title>
        <?= $this->js_css->get_js_string(); ?>
        <?= $this->js_css->get_css_string(); ?>
    </head>
    <body>
        <div class="layout-container">
            <?php if (!empty($menu) && is_array($menu)) : ?>
                <div class="sidebar-container navbar-collapse" id="left-menu">
                    <div class="sidebar-header">
                        <a href="<?= '/' . $this->config->item('admin_page') ?>" class="logo_sidebar"></a>
                    </div>
                    <div class="sidebar-content">
                        <ul class="sidebar-nav">
                            <?php foreach ($menu as $item) : ?>
                                <?php if (!empty($item['image'])) : ?>
                                    <li class="list-item <?= (!empty($item['page']) && strpos($this->uri->uri_string(), $item['page']) ? 'active' : '') ?>">
                                        <a <?= !empty($item['children']) ? 'class="collapsed"' : '' ?> href="<?= !empty($item['page']) ? '/' . $this->config->item('admin_page') . '/' . $item['page'] : '#' ?>">
                                            <i class="fa <?= $item['image'] ?>"></i>
                                            <span><?= $this->lang->line($item['translate']); ?></span>
                                            <i class="fa fa-angle-down"></i>
                                        </a>
                                        <?php if (!empty($item['children'])) : ?>
                                            <ul class="collapse">
                                                <?php foreach ($item['children'] as $citem) : ?>
                                                    <li <?= (strpos($this->uri->uri_string(), $citem['page']) ? 'class="active"' : ''); ?>>
                                                        <a href="/<?= $this->config->item('admin_page') . '/' . $citem['page']; ?>">
                                                            <?= $this->lang->line($citem['translate']); ?>
                                                        </a>
                                                    </li>
                                                <?php endforeach; ?>
                                            </ul>
                                        <?php endif; ?>
                                    </li>
                                <?php endif ?>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
            <?php else : ?>
                <?= is_string($menu) ? $menu : '' ?>
            <?php endif; ?>

            <header class="header-container">
                <nav>
                    <div class="pull-left active">
                        <a id="offcanvas-toggler" href="#" class="menu-link menu-link-slide"><span><em></em></span></a>
                    </div>
                    <h1 class="header-title">{title}</h1>
                    <ul class="pull-right user_profile">
                        <?php if ($this->rt_user->isAllowed('ciext_help', 'view_ciext_help')):?>
                            <li>
                                <a href="/<?= $this->load->library('ciext_help/parser/module_url_parser')->parse() ?>" title="<?= $this->lang->line('Ciext help') ?>">
                                    <i class="fa fa-question-circle-o"></i>
                                </a>
                            </li>
                        <?php endif; ?>
                        <li>
                            <a href="/" target="_blank"><i class="fa fa-home"></i></a>
                        </li>
                        <li class="dropdown">
                            {user_info}
                        </li>
                        <li class="dropdown">
                            <a href="/" data-toggle="dropdown" class="dropdown-toggle"><i class="fa fa-ellipsis-v"></i></a>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <?php foreach ($menu as $item) : ?>
                                    <li class="dropdown<?= (!empty($item['children'])) ? '-submenu pull-left' : '' ?>">
                                        <a href="<?= !empty($item['page']) ? '/' . $this->config->item('admin_page') . '/' . $item['page'] : '#' ?>">
                                            <span><?= $this->lang->line($item['translate']); ?></span>
                                        </a>
                                        <?php if (!empty($item['children'])) : ?>
                                            <ul class="dropdown-menu dropdown-menu-left">
                                                <?php foreach ($item['children'] as $citem) : ?>
                                                    <li <?= (strpos($this->uri->uri_string(), $citem['page']) ? 'class="active"' : ''); ?>>
                                                        <a href="/<?= $this->config->item('admin_page') . '/' . $citem['page']; ?>">
                                                            <?= $this->lang->line($citem['translate']); ?>
                                                        </a>
                                                    </li>
                                                <?php endforeach; ?>
                                            </ul>
                                        <?php endif; ?>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </li>
                    </ul>
                </nav>
            </header>
            <div class="main-container">
                <div class="content">
                    {content}
                    <footer>
                        {admin_footer}
                    </footer>
                </div>
            </div>
        </div>

    </body>
</html>