<?php if (!function_exists('renderMainMenu')) {
  function renderMainMenu($context, $item) {
    $journal3 = $context['journal3'];
    $display = $context['display'];
    $cid = $journal3->uniqueId('collapse-');
    $image_width = $context['image_width'];
    $image_height = $context['image_height'];
    ?>
    <li class="<?php echo $journal3->classes($item['classes']); ?>">
      <?php if ($item['items']): ?>
        <?php if ($item['link']['href']): ?>
          <a href="<?php echo $item['link']['href']; ?>" <?php echo $journal3->linkAttrs($item['link']); ?> <?php if ($display == 'dropdown'): ?> class="dropdown-toggle" data-toggle="dropdown" <?php else: ?> class="collapse-toggle"<?php endif; ?>>
            <?php if (!empty($item['thumb'])): ?>
            <span class="menu-image">
               <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
            </span>
            <?php endif; ?>
            <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
            <span class="open-menu collapsed" data-toggle="collapse" data-target="#<?php echo $cid; ?>"><em class="fa fa-plus"></em></span>
          </a>
        <?php else: ?>
          <a href="javascript:;" <?php if ($display == 'dropdown'): ?> class="dropdown-toggle" data-toggle="dropdown" <?php else: ?> class="collapse-toggle"<?php endif; ?>>
            <?php if (!empty($item['thumb'])): ?>
            <span class="menu-image">
               <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
            </span>
            <?php endif; ?>
            <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
            <span class="open-menu collapsed" data-toggle="collapse" data-target="#<?php echo $cid; ?>"><em class="fa fa-plus"></em></span>
          </a>
        <?php endif; ?>
        <div class="<?php echo $display == 'dropdown' ? 'dropdown-menu j-dropdown' : 'collapse'; ?>" id="<?php echo $cid; ?>">
          <ul class="j-menu">
            <?php foreach ($item['items'] as $subitem): ?>
              <?php renderMainMenu($context, $subitem); ?>
            <?php endforeach; ?>
          </ul>
        </div>
      <?php else: ?>
        <?php if ($item['link']['href']): ?>
          <a href="<?php echo $item['link']['href']; ?>" <?php echo $journal3->linkAttrs($item['link']); ?>>
            <?php if (!empty($item['thumb'])): ?>
              <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
            <?php endif; ?>
            <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
          </a>
        <?php else: ?>
          <a href="javascript:;">
            <?php if (!empty($item['thumb'])): ?>
              <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
            <?php endif; ?>
            <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
          </a>
        <?php endif; ?>
      <?php endif; ?>
    </li>
    <?php
  }
} ?>
<?php if ($items): ?>
  <div id="<?php echo $id; ?>" class="<?php echo $journal3->classes($classes); ?>">
    <button aria-label="Edit" class="admin-edit" type="button" data-edit="<?php echo $edit; ?>"><em class="fa fa-pencil" data-placement="auto" data-toggle="tooltip-hover" data-tooltip-class="admin-edit-tooltip" title="Edit <?php echo $name; ?>"></em></button>
    <ul class="j-menu"><?php foreach ($items as $item): ?>
        <?php $cid = $journal3->uniqueId('collapse-'); ?>
        <li class="<?php echo $journal3->classes($item['classes']); ?>" data-open-color-scheme="<?php echo $item['dropdown_color_scheme'] ?: $dropdown_color_scheme; ?>">
          <?php if ($item['items']): ?>
            <?php if ($item['link']['href']): ?>
              <a href="<?php echo $item['link']['href']; ?>" <?php echo $journal3->linkAttrs($item['link']); ?> <?php if ($display == 'dropdown'): ?> class="dropdown-toggle" data-toggle="dropdown" <?php else: ?> class="collapse-toggle"<?php endif; ?>>
                <?php if (!empty($item['thumb'])): ?>
                  <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
                <?php endif; ?>
                <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
                <span class="open-menu collapsed" data-toggle="collapse" data-target="#<?php echo $cid; ?>" <?php if ($item['isOpen']): ?>aria-expanded="true"<?php endif; ?>><em class="fa fa-plus"></em></span>
                <?php if ($item['label']): ?>
                  <span class="menu-label"><?php echo $item['label']; ?></span>
                <?php endif; ?>
              </a>
            <?php else: ?>
              <a href="javascript:;" <?php if ($display == 'dropdown'): ?> class="dropdown-toggle" data-toggle="dropdown" <?php else: ?> class="collapse-toggle"<?php endif; ?>>
                <?php if (!empty($item['thumb'])): ?>
                  <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
                <?php endif; ?>
                <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
                <span class="open-menu collapsed" data-toggle="collapse" data-target="#<?php echo $cid; ?>" <?php if ($item['isOpen']): ?>aria-expanded="true"<?php endif; ?>><em class="fa fa-plus"></em></span>
                <?php if ($item['label']): ?>
                  <span class="menu-label"><?php echo $item['label']; ?></span>
                <?php endif; ?>
              </a>
            <?php endif; ?>
            <?php if ($item['type'] == 'multilevel'): ?>
              <div class="<?php echo $display == 'dropdown' ? 'dropdown-menu j-dropdown' : 'collapse'; ?> <?php if ($item['isOpen']): ?>in<?php endif; ?> <?php echo $item['dropdown_color_scheme'] ?: $dropdown_color_scheme; ?>" id="<?php echo $cid; ?>">
                <?php echo !$item['isOpen'] ? '<template>' : ''; ?>
                <ul class="j-menu">
                  <?php foreach ($item['items'] as $subitem): ?>
                    <?php renderMainMenu(get_defined_vars(), $subitem); ?>
                  <?php endforeach; ?>
                </ul>
                <?php echo !$item['isOpen'] ? '</template>' : ''; ?>
              </div>
            <?php endif; ?>
            <?php if ($item['type'] == 'megamenu'): ?>
              <div class="<?php echo $display == 'dropdown' ? 'dropdown-menu j-dropdown' : 'collapse'; ?> <?php if ($item['isOpen']): ?>in<?php endif; ?> <?php echo $item['dropdown_color_scheme'] ?: $dropdown_color_scheme; ?>" id="<?php echo $cid; ?>">
                <?php echo !$item['isOpen'] ? '<template>' : ''; ?>
                <div class="mega-menu-content"><?php echo $item['items']; ?></div>
                <?php echo !$item['isOpen'] ? '</template>' : ''; ?>
              </div>
            <?php endif; ?>
            <?php if ($item['type'] == 'flyout'): ?>
              <div class="<?php echo $display == 'dropdown' ? 'dropdown-menu j-dropdown' : 'collapse'; ?> <?php if ($item['isOpen']): ?>in<?php endif; ?> <?php echo $item['dropdown_color_scheme'] ?: $dropdown_color_scheme; ?>" id="<?php echo $cid; ?>">
                <?php echo $item['items']; ?>
              </div>
            <?php endif; ?>
          <?php else: ?>
            <?php if ($item['link']['href']): ?>
              <a href="<?php echo $item['link']['href']; ?>" <?php echo $journal3->linkAttrs($item['link']); ?>>
                <?php if (!empty($item['thumb'])): ?>
                  <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
                <?php endif; ?>
                <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
                <?php if ($item['label']): ?>
                  <span class="menu-label"><?php echo $item['label']; ?></span>
                <?php endif; ?>
              </a>
            <?php else: ?>
              <a href="javascript:;" title="<?php echo $item['title']; ?>">
                <?php if (!empty($item['thumb'])): ?>
                  <img src="<?php echo $item['thumb']; ?>" <?php if (!empty($item['thumb2x'])): ?>srcset="<?php echo $item['thumb']; ?> 1x, <?php echo $item['thumb2x']; ?> 2x" <?php endif; ?> alt="<?php echo $item['title']; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" loading="lazy"/>
                <?php endif; ?>
                <?php echo $journal3->countBadge($item['title'], $item['link']['total'], $item['link']['classes']); ?>
                <?php if ($item['label']): ?>
                  <span class="menu-label"><?php echo $item['label']; ?></span>
                <?php endif; ?>
              </a>
            <?php endif; ?>
          <?php endif; ?>
        </li>
      <?php endforeach; ?>
    </ul>
  </div>
<?php endif; ?>
