<?php helper('menu'); ?>

<aside class="main-sidebar sidebar-dark-primary elevation-4">
    <a href="<?= site_url('dashboard') ?>" class="brand-link text-center">
        <span class="brand-text font-weight-bold">SIMSEKO</span>
    </a>

    <div class="sidebar">
        <nav class="mt-2">
            <ul class="nav nav-pills nav-sidebar flex-column"
                data-widget="treeview" data-accordion="false">

                <?php foreach ($menus as $menu): ?>
                    <?php if (!isset($menu['children'])): ?>

                        <li class="nav-item">
                            <a href="<?= site_url($menu['url']) ?>"
                               class="nav-link <?= isActive($menu['url']) ?>">
                                <i class="nav-icon <?= $menu['icon'] ?>"></i>
                                <p><?= esc($menu['title']) ?></p>
                            </a>
                        </li>

                    <?php else: ?>
                        <?php $parentSegment = explode('/', $menu['children'][0]['url'])[0]; ?>

                        <li class="nav-item <?= isOpenMenu($parentSegment) ?>">
                            <a href="#" class="nav-link">
                                <i class="nav-icon <?= $menu['icon'] ?>"></i>
                                <p>
                                    <?= esc($menu['title']) ?>
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>

                            <ul class="nav nav-treeview">
                                <?php foreach ($menu['children'] as $child): ?>
                                    <li class="nav-item">
                                        <a href="<?= site_url($child['url']) ?>"
                                           class="nav-link <?= isActive($child['url']) ?>">
                                            <i class="far fa-circle nav-icon"></i>
                                            <p><?= esc($child['title']) ?></p>
                                        </a>
                                    </li>
                                <?php endforeach ?>
                            </ul>
                        </li>

                    <?php endif ?>
                <?php endforeach ?>

            </ul>
        </nav>
    </div>
</aside>
