<?php
$blnHasActive = false;
$intLevel = (int) substr($this->level, 6);

if ($intLevel < 1) {
    $intLevel = 1;
}

if (1 == $intLevel):
    $arrLanguages = Contao\System::getContainer()->get('contao.intl.locales')->getLocales(null, true);

    foreach ($this->items as $item) {
        if ($item['isActive'] || str_contains($item['subitems'], 'class="active')) {
            $blnHasActive = true;
            break;
        }
    }
    ?>
<select class="<?= $this->level; ?>" onchange="window.location.href=this.value">
<?php endif; ?>
<?php if (1 == $intLevel && !$blnHasActive): ?><option value="">-</option><?php endif; ?>
<?php foreach ($this->items as $item): ?>
<?php if ($item['isActive']): ?>
<option class="active <?= $item['class']; ?>" selected><?= str_repeat('&nbsp;&nbsp;&nbsp;', $intLevel - 1); ?><?= $arrLanguages[$item['item']->getLocaleId()] ?? $item['link']; ?><?= $item['subitems']; ?></option>
<?php else: ?>
<option <?php if ($item['class']): ?> class="<?= $item['class']; ?>"<?php endif; ?> value="<?= $item['href']; ?>"><?= str_repeat('&nbsp;&nbsp;&nbsp;', $intLevel - 1); ?><?= $arrLanguages[$item['item']->getLocaleId()] ?? $item['link']; ?><?= $item['subitems']; ?></option>
<?php endif; ?>
<?php endforeach; ?>
<?php if (1 == $intLevel): ?>
</select>
<?php endif; ?>
