<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://xavis.co.kr"
      class="logo-link logo-link-xavis"
      target="_blank"
      rel="noopener noreferrer"
      aria-label="XAVIS 회사 사이트(새 탭)"
    >
      <img src="/public/images/xavis-logo.png" alt="XAVIS" class="logo-img logo-img-xavis" />
    </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>
  <a href="/chat" class="nav-item <%= activeMenu === 'chat' ? 'active' : '' %>">채팅</a>
  <a href="/ai-explore" class="nav-item <%= activeMenu === 'ai-explore' ? 'active' : '' %>">AI</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' : '' %>">성공사례</a>
  <div class="nav-footer">
    <% var _opsLoggedIn = typeof opsUserEmail !== 'undefined' && opsUserEmail; %>
    <% if (_opsLoggedIn) { %>
    <a href="/logout" class="nav-item nav-item-ops-logout" title="이메일 인증 세션 종료">로그아웃</a>
    <% } else { %>
    <% if (typeof adminMode !== 'undefined' && adminMode) { %>
    <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="관리자 세션 종료">로그오프</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') %>
