<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_menu
 *
 * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Helper\ModuleHelper;

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('mod_menu', 'mod_menu/menu.min.js', [], ['type' => 'module']);
$wa->registerAndUseScript('mod_menu', 'mod_menu/menu-es5.min.js', [], ['nomodule' => true, 'defer' => true]);

$id = '';

if ($tagId = $params->get('tag_id', ''))
{
	$id = ' id="' . $tagId . '"';
}

//Slight modifications to the menu output to play nicely with Bootstrap
// The menu class is deprecated. Use mod-menu instead
?>
<ul <?php echo $id; ?> class="mobile_menu cat-menu menu d-lg-flex align-items-center">
<?php foreach ($list as $i => &$item)
{
	$itemParams = $item->getParams();
	$class      = 'nav-item item-' . $item->id;
	
	if ($item->id == $default_id)
	{
		$class .= ' default';
	}

	if ($item->id == $active_id || ($item->type === 'alias' && $itemParams->get('aliasoptions') == $active_id))
	{
		$class .= ' current';
	}

	if (in_array($item->id, $path))
	{
		$class .= ' active';
	}
	elseif ($item->type === 'alias')
	{
		$aliasToId = $itemParams->get('aliasoptions');

		if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
		{
			$class .= ' active';
		}
		elseif (in_array($aliasToId, $path))
		{
			$class .= ' alias-parent-active';
		}
	}

	if ($item->type === 'separator')
	{
		$class .= ' divider';
	}

	if ($item->deeper)
	{
		$class .= ' dropdown';
	}

	if ($item->parent)
	{
		$class .= ' parent';
	}
	
	if ($item->anchor_title == 'delimiter')
	{
		$class .= ' delimiter';
	}
	if ($item->anchor_title == 'mutter')
	{
		$class .= ' mutter';
	}

	echo '<li class="' . $class . '">';

	switch ($item->type) :
		case 'separator':
		case 'component':
		case 'heading':
		case 'url':
			require ModuleHelper::getLayoutPath('mod_menu', 'catservice_' . $item->type);
			break;

		default:
			require ModuleHelper::getLayoutPath('mod_menu', 'catservice_url');
			break;
	endswitch;

	// The next item is deeper.
	if ($item->deeper)
	{
		echo '<ul class="dropdown-menu">';
	}
	// The next item is shallower.
	elseif ($item->shallower)
	{
		echo '</li>';
		echo str_repeat('</ul></li>', $item->level_diff);
	}
	// The next item is on the same level.
	else
	{
		echo '</li>';
	}
}
?></ul>
<div class="mobile_menu mobile_menu_box">
	<div class="ba-phone">
		<?php
			$document = &JFactory::getDocument();
			$renderer = $document->loadRenderer('modules');
			$options = array('style' => 'none');
			$position = 'topbar';
			echo $renderer->render($position, $options, null);
		?>
	</div>
	<?php
		$document = &JFactory::getDocument();
		$renderer = $document->loadRenderer('modules');
		$options = array('style' => 'none');
		$position = 'city-mail';
		echo $renderer->render($position, $options, null);
	?>
	<?php
		$document = &JFactory::getDocument();
		$renderer = $document->loadRenderer('modules');
		$options = array('style' => 'none');
		$position = 'footer4';
		echo $renderer->render($position, $options, null);
	?>
</div>