<?php
if ($post['content'] != '') {
    $menuitems = json_decode($post['content'], true);
    $menuitems = $menuitems[0];
    foreach ($menuitems as &$menuitem) {
        $menuitem['title'] = $db->table('menuitems')->where('id', '=', $menuitem['id'])->get_var('title');
        $menuitem['type'] = $db->table('menuitems')->where('id', '=', $menuitem['id'])->get_var('type');
        $menuitem['slug'] = $db->table('menuitems')->where('id', '=', $menuitem['id'])->get_var('slug');
        $menuitem['target'] = $db->table('menuitems')->where('id', '=', $menuitem['id'])->get_var('target');

        if (!empty($menuitem['children'][0])) {
            foreach ($menuitem['children'][0] as &$child) {
                $child['title'] = $db->table('menuitems')->where('id', '=', $child['id'])->get_var('title');
                $child['type'] = $db->table('menuitems')->where('id', '=', $child['id'])->get_var('type');
                $child['slug'] = $db->table('menuitems')->where('id', '=', $child['id'])->get_var('slug');
                $child['target'] = $db->table('menuitems')->where('id', '=', $child['id'])->get_var('target');
                if (!empty($child['children'][0])) {
                    foreach ($child['children'][0] as &$child1) {
                        $child1['title'] = $db->table('menuitems')->where('id', '=', $child1['id'])->get_var('title');
                        $child1['type'] = $db->table('menuitems')->where('id', '=', $child1['id'])->get_var('type');
                        $child1['slug'] = $db->table('menuitems')->where('id', '=', $child1['id'])->get_var('slug');
                        $child1['target'] = $db->table('menuitems')->where('id', '=', $child1['id'])->get_var('target');
                        if (!empty($child1['children'][0])) {
                            foreach ($child1['children'][0] as &$child2) {
                                $child2['title'] = $db->table('menuitems')->where('id', '=', $child2['id'])->get_var('title');
                                $child2['type'] = $db->table('menuitems')->where('id', '=', $child2['id'])->get_var('type');
                                $child2['slug'] = $db->table('menuitems')->where('id', '=', $child2['id'])->get_var('slug');
                                $child2['target'] = $db->table('menuitems')->where('id', '=', $child2['id'])->get_var('target');
                            }
                        }
                    }
                }
            }
        }
    }
} else {
    $menuitems = menu_Items('data', $post['id']);
}
$current_url = $_SERVER['REQUEST_URI'];
$class = ($post['url'] === $current_url) ? 'active' : '';
?>
<?php
if (menu_Items('total_count', $post['id'])) {
    ?>
    <ul  class="menu " data-vvveb-disabled-noback>
        <?php
        foreach ($menuitems as $key => $item) {
            ?>
            <li >
            <?php if ($item['children'][0]){ ?> <span class="drop-btn"><?= $item['title'] ?></span> <?php } else { ?> <a href="<?= $item['slug'] ?>"><?= $item['title'] ?></a> <?php } ?>
                <?php if ($item['children'][0]) { ?>
                    <ul class="drop-box">
                        <?php foreach ($item['children'][0] as $childkey => $childmenu) { ?>
                                <li ><a href="<?= $childmenu['slug'] ?>"><?= $childmenu['title'] ?></a></li>
                        <?php } ?>
                    </ul>
                <?php } ?>
            </li>
        <?php } ?>
    </ul>
    <?php
}
