<?php
/* @var $container Zend\Navigation\Navigation */
$container = $this->container;
?>
<ul class="nav" id="side-menu">
    <?php foreach ($container as $page) : ?>
        <?php if (!$this->navigation()->accept($page)) {
            continue;
        }
        $hasPages = false;

        if ($page->hasPages()) :
            foreach ($page->getPages() as $child) :
                if ($this->navigation()->accept($child)) :
                    $hasPages = true;
                    break;
                endif;
            endforeach;
        endif;

        ?>
        <li class="<?= $page->isActive(true) ? 'active' : '' ?>">
            <a class="<?= $page->getClass() ?><?= $page->isActive(true) ? ' active' : '' ?>"
               href="<?= $page->getHref() ?>"
                <?php if (null !== $page->getTarget()): ?>
                    target="<?= $page->getTarget(); ?>"
                <?php endif; ?>
            >
                <i class="fa fa-circle-o" aria-hidden="true"></i>
                <?= $this->escapeHtml(
                    $this->translate($page->getLabel(),
                        $this->navigation($container)->getTranslatorTextDomain())
                );
                ?>
                <?= $hasPages ? '<span class="fa arrow"></span>' : '' ?>
            </a>
            <?php if ($hasPages) : ?>
                <ul class="nav nav-second-level">
                    <?php /** @var Zend\Navigation\Page\AbstractPage $child */ ?>
                    <?php foreach ($page as $child) : ?>
                        <?php if (!$this->navigation()->accept($child)) {
                            continue;
                        } ?>
                        <?php if ($child->get("separator") === true): ?>
                            <li class="divider"></li>
                            <?php
                            continue;
                        endif;
                        ?>
                        <li<?= $page->isActive(true) ? ' class="active"' : '' ?>>
                            <a href="<?= $child->getHref() ?>"
                               class="<?= $child->getClass() ?><?= $child->isActive(true) ? ' active' : '' ?>"
                                <?php if (null !== $child->getTarget()): ?>
                                    target="<?= $child->getTarget(); ?>"
                                <?php endif; ?> >
                                <?= $this->escapeHtml(
                                    $this->translate($child->getLabel(),
                                        $this->navigation($container)->getTranslatorTextDomain())
                                );
                                ?>
                            </a>
                        </li>
                    <?php endforeach ?>
                </ul>
            <?php endif; ?>
        </li>
    <?php endforeach ?>
</ul>