<div class="app-sidebar sidebar-shadow">
    <div class="app-header__logo">
        <div class="logo-src"></div>
        <div class="header__pane ms-auto">
            <div>
                <button type="button" class="hamburger close-sidebar-btn hamburger--elastic"
                    data-class="closed-sidebar">
                    <span class="hamburger-box">
                        <span class="hamburger-inner"></span>
                    </span>
                </button>
            </div>
        </div>
    </div>
    <div class="app-header__mobile-menu">
        <div>
            <button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
                <span class="hamburger-box">
                    <span class="hamburger-inner"></span>
                </span>
            </button>
        </div>
    </div>
    <div class="app-header__menu">
        <span>
            <button type="button" class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
                <span class="btn-icon-wrapper">
                    <i class="fa fa-ellipsis-v fa-w-6"></i>
                </span>
            </button>
        </span>
    </div>
    <div class="scrollbar-sidebar">
        <div class="app-sidebar__inner">
            <ul class="vertical-nav-menu">

                <li class="app-sidebar__heading">컨펌스
                    <?php
                    $serverIp = $_SERVER['SERVER_ADDR'] ?? '';

                    // 개발 서버
                    $devServers = ['192.168.200.8', '192.168.10.231', '172.18.0.5'];

                    // 도커 테스트 서버
                    $dockerServers = ['172.18.0.2'];

                    // 테스트 서버
                    $testServers = ['192.168.200.9', '192.168.10.237', '175.126.191.182', '192.168.10.243'];

                    // 운영 서버 IP 매핑
                    $prodServers = [
                        '172.16.100.2' => "WEB 1",
                        '172.16.100.3' => "WEB 2",
                        '172.16.100.4' => "WEB 3",
                        '172.16.100.5' => "WEB 4",
                    ];


                    if (in_array($serverIp, $devServers, true)) {
                        // 개발
                        echo "개발";

                    } elseif (in_array($serverIp, $dockerServers, true)) {
                        // 도커
                        echo "
                            <div style='width:180px; height:43px;text-align:center;
                                        font-size:12px;color:#ffffff;font-weight:bold;
                                        padding-top:2px;background-color:#0000ff'>
                                DOCKER <br>{$serverIp}<br>{$this->load->db->hostname}
                            </div>
                        ";

                    } elseif (in_array($serverIp, $testServers, true)) {
                        // 테스트
                        echo "테스트";

                    } else {
                        // 운영
                        $serverName = $prodServers[$serverIp] ?? 'UNKNOWN';

                        echo "{$serverName}";
                    }
                    ?>

                </li>

                <?php $path = strtok($_SERVER['REQUEST_URI'], '?'); ?>

                <?php foreach ($mMenu as $menu): ?>

                    <?php
                    // 이 부모(menu)의 자식 중 현재 path와 일치하는 메뉴가 있는지 체크
                    $hasActiveChild = false;

                    $path = parse_url($path, PHP_URL_PATH);
                    // 2. 숫자 파라미터 제거 (/detail/123 → /detail)
                    $path = preg_replace('#/\d+#', '', $path);

                    // 3. 끝 슬래시 정리
                    $path = rtrim($path, '/');
                    switch ($path) {
                        case "/article/receipt/detail":
                            $path = "/article/receipt/lists";
                            break;
                        case "/article/dept/detail":
                            $path = "/article/dept/lists";
                            break;
                        case "/article/record/detail":
                            $path = "/article/record/lists";
                            break;
                        case "/board/notice/write":
                        case "/board/notice/modify":
                        case "/board/notice/detail":
                            $path = "/board/notice/lists";
                            break;

                        case "/m701/m701a/detail":
                            $path = "/m701/m701a/lists";
                            break;
                        case "/m702/m702a/detail":
                            $path = "/m702/m702a/lists";
                            break;
                        case "/m703/m703a/detail":
                            $path = "/m703/m703a/lists";
                            break;
                        case "/m704/m704a/detail":
                            $path = "/m704/m704a/lists";
                            break;
                        case "/m705/m705a/detail":
                            $path = "/m705/m705a/lists";
                            break;
                        case "/m706/m706a/detail":
                            $path = "/m706/m706a/lists";
                            break;
                        case "/m708/m708a/detail":
                            $path = "/m708/m708a/lists";
                            break;
                        case "/m709/m709a/detail":
                            $path = "/m709/m709a/lists";
                            break;
                        case "/m710/m710a/detail":
                            $path = "/m710/m710a/lists";
                            break;
                        case "/m711/m711a/detail":
                            $path = "/m711/m711a/lists";
                            break;
                        case "/m712/m712a/detail":
                            $path = "/m712/m712a/lists";
                            break;
                        case "/m713/m713a/detail":
                            $path = "/m713/m713a/lists";
                            break;
                        case "/article/apt/detail":
                            $path = "/article/apt/lists";
                            break;
                        case "/article/apt/ground/detail":
                            $path = "/article/apt/lists2";
                            break;


                    }
                    foreach ($sMenu as $subMenu) {
                        if ($menu["mnu_id"] == $subMenu["mnu_pid"] && $path === $subMenu["mnu_url"]) {
                            $hasActiveChild = true;
                            break;
                        }
                    }
                    ?>

                    <li class="<?= $hasActiveChild ? 'mm-active' : '' ?>">
                        <?php if ($menu["mnu_pid"] == '0'): ?>
                            <a href="#" class="<?= $hasActiveChild ? 'mm-active' : '' ?>">
                                <i class="metismenu-icon <?= $icons[$menu['mnu_id']] ?>"></i>
                                <?= $menu["mnu_nm"] ?>
                                <i class="metismenu-state-icon pe-7s-angle-down caret-left"></i>
                            </a>
                        <?php endif; ?>

                        <ul>
                            <?php foreach ($sMenu as $subMenu): ?>
                                <?php if ($menu["mnu_id"] == $subMenu["mnu_pid"]): ?>
                                    <li>
                                        <a href="<?= $subMenu["mnu_url"] ?>"
                                            class="<?= $path === $subMenu['mnu_url'] ? 'mm-active' : '' ?>">
                                            <i class="metismenu-icon"></i>
                                            <?= $subMenu["mnu_nm"] ?>
                                        </a>
                                    </li>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </ul>
                    </li>

                <?php endforeach; ?>



            </ul>
        </div>
    </div>
</div>