<?php
/**
 * Landofcoder
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Landofcoder.com license that is
 * available through the world-wide-web at this URL:
 * https://landofcoder.com/terms
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category   Landofcoder
 * @package    Lof_Formbuilder
 * @copyright  Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
 * @license    https://landofcoder.com/terms
 */

/* @var $block Menu */

use Lof\All\Block\Adminhtml\Menu;

?>
<div class="landofcoder-menu">
    <div class="actions dropdown closable">
        <button type="button" class="admin__action-dropdown" data-mage-init='{"dropdown":{}}' data-toggle="dropdown" aria-haspopup="true">
            <span class="admin__action-dropdown-text"><?= $block->getCurrentItem()['title'] ?></span>
        </button>
        <ul class="dropdown-menu">
            <?php $isCurrent = false;
$i = 0; ?>
            <?php foreach ($block->getMenuItems() as $index => $item): ?>
                <?php
    $hasChild = false;
                if (isset($item['child']) && $item['child']) {
                    $hasChild = true;
                }
                if ($block->isCurrent($index)) {
                    $isCurrent = true;
                }
                if ($isCurrent) {
                    $i++;
                }
                ?>
                <li class="<?= $i ?> <?php if ($isCurrent && $i == 1): ?>current<?php endif; ?> <?php if (isset($item['separator'])): ?>separator<?php endif; ?> <?php if ($hasChild): ?>has-child is-parent-menu dropdown-child<?php endif; ?> level0">
                    <a href="<?= $item['url'] ?>" class="<?php if ($hasChild): ?>dropbtn<?php endif; ?>" <?= $block->renderAttributes($item) ?>><?= $item['title'] ?></a>
                    <?php if ($hasChild) { ?>
                    <ul class="dropdown-menu-child dropdown-content">
                        <?php foreach ($item['child'] as $child_index => $child_item) { ?>
                        <li class="<?php if ($isCurrent && $i == 1): ?>current<?php endif; ?> <?php if (isset($child_item['separator'])): ?>separator<?php endif; ?> menu-child level1">
                         <a href="<?= $child_item['url'] ?>" <?= $block->renderAttributes($child_item) ?>><?= $child_item['title'] ?></a>
                        </li>
                    <?php } ?>
                    </ul>
                    <?php } ?>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
</div>
