<button type="button" class="nav-mobile-toggle" id="nav-mobile-toggle" aria-label="메뉴 열기" aria-expanded="false" aria-controls="nav-drawer">
  <svg width="22" height="22" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path fill="currentColor" d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>
</button>
<div class="nav-drawer-backdrop" id="nav-drawer-backdrop" hidden></div>
<aside class="left-nav" id="nav-drawer">
  <div class="nav-logo-section">
    <a
      href="https://ncue.net"
      class="logo-link logo-link-ncue"
      target="_blank"
      rel="noopener noreferrer"
      aria-label="NCue 회사 사이트(새 탭)"
    >
      <img src="/public/images/ncue-logo.png" alt="NCue" class="logo-img logo-img-ncue" />
    </a>
    <img
      src="/public/images/aiplatform-logo.png"
      alt="AI PLATFORM"
      class="logo-img logo-img-aiplatform"
      width="168"
      height="auto"
      decoding="async"
    />
    <div class="nav-logo-divider" role="presentation" aria-hidden="true"></div>
  </div>
  <% var _guideBotOk = typeof guideBotMenuAllowed !== "undefined" && guideBotMenuAllowed; %>
  <% if (_guideBotOk) { %>
  <a href="/guide-bot" class="nav-item <%= activeMenu === 'guide-bot' ? 'active' : '' %>">가이드봇</a>
  <a href="/wm" class="nav-item <%= activeMenu === 'wm' ? 'active' : '' %>">WM</a>
  <% } %>
  <div class="nav-separator"></div>
  <a href="/ai-explore" class="nav-item <%= activeMenu === 'ai-explore' ? 'active' : '' %>">AI</a>
  <a href="/ai-explore/prompts" class="nav-item <%= activeMenu === 'prompts' ? 'active' : '' %>">프롬프트</a>
  <a href="/learning" class="nav-item <%= activeMenu === 'learning' ? 'active' : '' %>">학습센터</a>
  <a href="/ax-apply" class="nav-item <%= activeMenu === 'ax-apply' ? 'active' : '' %>">과제신청</a>
  <a href="/ai-cases" class="nav-item <%= activeMenu === 'ai-cases' ? 'active' : '' %>">AI 활용 사례</a>
  <% var _dashOk = typeof dashboardMenuAllowed !== 'undefined' && dashboardMenuAllowed; %>
  <% if (_dashOk) { %>
  <div class="nav-separator"></div>
  <a href="/dashboard" class="nav-item <%= activeMenu === 'dashboard' ? 'active' : '' %>">대시보드</a>
  <% } %>
  <div class="nav-footer">
    <% var _opsLoggedIn = typeof opsUserEmail !== 'undefined' && opsUserEmail; %>
    <% var _admin = typeof adminMode !== 'undefined' && adminMode; %>
    <% if (_opsLoggedIn) { %>
      <% if (_admin) { %>
    <a href="/admin/users" class="nav-item <%= activeMenu === 'admin-users' ? 'active' : '' %>">사용자 현황관리</a>
    <div class="nav-separator"></div>
    <a href="/admin/logout" class="nav-item nav-item-ghost" title="관리자 모드 종료 후 학습센터 목록으로">관리자 off</a>
    <div class="nav-separator nav-separator-between-footer"></div>
    <a href="/logout" class="nav-item nav-item-ops-logout" title="이메일 인증 세션 종료">로그아웃</a>
      <% } else { %>
    <button type="button" class="nav-item nav-item-admin-entry" onclick="openAdminTokenModal()" title="관리자 토큰으로 인증">관리자</button>
    <div class="nav-separator nav-separator-between-footer"></div>
    <a href="/logout" class="nav-item nav-item-ops-logout" title="이메일 인증 세션 종료">로그아웃</a>
      <% } %>
    <% } else if (_admin) { %>
    <a href="/admin/users" class="nav-item <%= activeMenu === 'admin-users' ? 'active' : '' %>">사용자 현황관리</a>
    <div class="nav-separator"></div>
    <a href="/admin/logout" class="nav-item nav-item-ghost" title="관리자 모드 종료 후 학습센터 목록으로">관리자 off</a>
    <% } else { %>
    <div class="nav-separator"></div>
    <button type="button" class="nav-item nav-item-ghost" onclick="openAdminTokenModal()" title="관리자 모드">관리자</button>
    <% } %>
  </div>
</aside>
<script>
(function () {
  var toggle = document.getElementById("nav-mobile-toggle");
  var nav = document.getElementById("nav-drawer");
  var backdrop = document.getElementById("nav-drawer-backdrop");
  if (!toggle || !nav || !backdrop) return;

  function isMobileNav() {
    return typeof window.matchMedia === "function" && window.matchMedia("(max-width: 900px)").matches;
  }

  function openDrawer() {
    if (!isMobileNav()) return;
    nav.classList.add("nav-drawer-open");
    backdrop.removeAttribute("hidden");
    document.body.classList.add("nav-mobile-open");
    toggle.setAttribute("aria-expanded", "true");
    toggle.setAttribute("aria-label", "메뉴 닫기");
  }

  function closeDrawer() {
    nav.classList.remove("nav-drawer-open");
    backdrop.setAttribute("hidden", "");
    document.body.classList.remove("nav-mobile-open");
    toggle.setAttribute("aria-expanded", "false");
    toggle.setAttribute("aria-label", "메뉴 열기");
  }

  function toggleDrawer() {
    if (nav.classList.contains("nav-drawer-open")) closeDrawer();
    else openDrawer();
  }

  toggle.addEventListener("click", function (e) {
    e.stopPropagation();
    toggleDrawer();
  });
  backdrop.addEventListener("click", closeDrawer);

  nav.querySelectorAll("a").forEach(function (el) {
    el.addEventListener("click", function () {
      if (isMobileNav()) closeDrawer();
    });
  });
  nav.querySelectorAll("button.nav-item").forEach(function (el) {
    el.addEventListener("click", function () {
      if (isMobileNav()) closeDrawer();
    });
  });

  document.addEventListener("keydown", function (e) {
    if (e.key === "Escape" && nav.classList.contains("nav-drawer-open")) closeDrawer();
  });

  if (typeof window.matchMedia === "function") {
    window.matchMedia("(min-width: 901px)").addEventListener("change", function (ev) {
      if (ev.matches) closeDrawer();
    });
  }
})();

(function () {
  try {
    var sp = new URLSearchParams(window.location.search);
    if (sp.get("verified") === "1") {
      alert("인증되었습니다.");
      var u = new URL(window.location.href);
      u.searchParams.delete("verified");
      history.replaceState({}, "", u.pathname + (u.search ? u.search : "") + u.hash);
    }
  } catch (e) {}
})();
</script>
<%- include('admin-token-modal') %>
