<?
if ($logged) {
    $idmenu = getIdAdmMenu($_level);
    $nlink = count($a_lnkmenu[$idmenu]);
    $msid = "";

    $isModern = (isset($_gui) && $_gui == "modern");
    $mapIcon = function ($sectionKey, $label) {
        $k = strtolower((string)$sectionKey . " " . (string)$label);
        if (strpos($k, "dashboard") !== false || strpos($k, "home") !== false) return "bi-grid-1x2-fill";
        if (strpos($k, "virtual") !== false || strpos($k, "assistant") !== false || strpos($k, "chatbot") !== false) return "bi-robot";
        if (strpos($k, "scontrin") !== false || strpos($k, "ticket") !== false) return "bi-receipt";
        if (strpos($k, "concor") !== false) return "bi-ticket-perforated";
        if (strpos($k, "email") !== false || strpos($k, "mail") !== false) return "bi-envelope";
        if (strpos($k, "utente") !== false || strpos($k, "account") !== false || strpos($k, "profilo") !== false) return "bi-person-circle";
        if (strpos($k, "anagrafic") !== false || strpos($k, "grupp") !== false || strpos($k, "operator") !== false) return "bi-people";
        if (strpos($k, "impost") !== false || strpos($k, "config") !== false || strpos($k, "setting") !== false) return "bi-sliders";
        if (strpos($k, "elenco") !== false || strpos($k, "list") !== false || strpos($k, "table") !== false) return "bi-table";
        if (strpos($k, "stat") !== false || strpos($k, "report") !== false) return "bi-bar-chart";
        if (strpos($k, "cms") !== false || strpos($k, "conten") !== false || strpos($k, "page") !== false) return "bi-journal-text";
        if (strpos($k, "doc") !== false || strpos($k, "knowledge") !== false) return "bi-folder2-open";
        return "bi-circle";
    };

    if ($isModern) {
        if ($_logow) {
            ?>
            <div class="brand">
            <div id="logoAzienda">
            <?
            WriteMedia("logow", $language, "max-width:160px");
            ?>
            </div></div>
            <?
        }
        ?>
        <nav class="menu" id="mainMenu">
        <?
        for ($i = 0; $i < $nlink; $i++) {
            $sectionKey = $a_sezmenu[$idmenu][$i];
            $label = trim(ucfirst(strtolower($a_lnkmenu[$idmenu][$i])));
            $href = "index.php?sz=" . $sectionKey . "&" . $msid . "&language=$language";
            $isActive = ($isezione == $a_isezmenu[$idmenu][$i]);
            $itemClass = "menu__item";
            if ($isActive) $itemClass .= " is-active";
            $iconClass = $mapIcon($sectionKey, $label);
            ?>
            <a class="<?= $itemClass ?>" href="<?= $href ?>" onclick="waitpage();">
                <i class="bi <?= $iconClass ?>"></i>
                <span><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?></span>
            </a>
            <?
        }
        ?>
            <a class="menu__item" href="javascript:logout()" title="Logout">
                <i class="bi bi-box-arrow-right"></i>
                <span>Logout</span>
            </a>
        </nav>
        <?
        if ($_foomini) {
            ?>
            <div class="sidebar__foot">
                <div class="sidebar__foot-title">Info</div>
                <div class="sidebar__foot-text"><?= Get_TXTArea('_foomini', $language) ?></div>
            </div>
            <?
        }
    } else {
        if($_logow) {
            ?>
            <div id="logoAzienda">
            <?
            WriteMedia("logow",$language,"max-width:120px");
            ?>
            </div>
            <?
        }
        ?>
        <ul class="menu5" id="mainMenu">
        <?
        for ($i = 0; $i < $nlink; $i++) {

            $szi = $a_sezmenu[$idmenu][$i];
            $skip = false;
            if (!$skip) {

                $href = "index.php?sz=" . $a_sezmenu[$idmenu][$i] . "&" . $msid . "&language=$language";

                $class = "menu5off";
                if ($isezione == $a_isezmenu[$idmenu][$i]) {
                    $class = "menu5on";
                }
                ?>
                <li class="<?= $class . " " . $a_sezmenu[$idmenu][$i] ?>" onclick="location.replace('<?= $href ?>')">
                    <a href="<?= $href ?>" onclick="waitpage();">
                        <div class="labelmenu"><? echo trim(ucfirst(strtolower($a_lnkmenu[$idmenu][$i]))); ?></div>
                    </a>
                </li>

                <?
            }
        }
        ?>
            <li class="menu5off logout" onclick="logout()">
                <a href="javascript:logout()" title="Logout">
                    <div class="labelmenu">Logout</div>
                </a>
            </li>
        </ul>

        <? if (isset($_menuleft) && $_menuleft == "minimized") { ?>
        <ul class="menu5" id="openCloseMenu">
            <li class="menu5off openmenu cliccabile" onclick="openCloseMenu()"></li>
        </ul>
        <? } ?>

        <? if($_level<=$MAXUSERSLEVEL) { ?>
        <div style="position:absolute;bottom:30px;">
            <? WriteMedia("logow",$language,"max-width:180px;margin-left:10px");?>
        </div>
        <? } ?>
        <?
    }
}

if($_foomini && (!$logged || !isset($_gui) || $_gui != "modern")) {
?>
<div id="foomini" style="position:absolute;bottom:10px;text-align:center;width:100%;color:#f7f7f7" class="testosm"><?=Get_TXTArea('_foomini', $language)?></div>
<? } ?>
