<!doctype html>
<html lang="en">
<head>
  <%- include('head', { title }) %>
</head>
<body>
<a class="skip-link" href="#main">Skip to content</a>
<header class="topbar">
  <div class="topbar-inner">
    <a class="brand" href="/dashboard" aria-label="GAPTECH Solutions — dashboard"><img src="/images/logo.png" alt="GAPTECH Solutions Ltd"></a>
    <% if (user) { %>
      <button class="nav-toggle" type="button" aria-expanded="false" aria-controls="primary-nav" data-nav-toggle><span aria-hidden="true"></span><span aria-hidden="true"></span><span aria-hidden="true"></span><span class="visually-hidden">Menu</span></button>
      <nav id="primary-nav" class="primary-nav" aria-label="Primary">
        <a class="<%= path === '/dashboard' ? 'active' : '' %>" href="/dashboard">Dashboard</a>
        <% if (user.role === 'wallet_admin' || user.position_level === 'admin') { %>
          <a class="<%= path.startsWith('/requests') && !(path === '/requests/new' && typeof type !== 'undefined' && type === 'leave') ? 'active' : '' %>" href="/requests?type=requisition">Stock Requisitions</a>
          <a class="<%= path === '/admin/stock' ? 'active' : '' %>" href="/admin/stock">Master Database</a>
          <a class="<%= path === '/requests/new' && typeof type !== 'undefined' && type === 'leave' ? 'active' : '' %>" href="/requests/new?type=leave">Leave</a>
        <% } else if (user.role === 'staff') { %>
          <a class="<%= path.startsWith('/requests') && !(path === '/requests/new' && typeof type !== 'undefined' && type === 'leave') ? 'active' : '' %>" href="/requests">Requisitions</a>
          <a class="<%= path === '/requests/new' && typeof type !== 'undefined' && type === 'leave' ? 'active' : '' %>" href="/requests/new?type=leave">Leave</a>
        <% } else { %>
          <a class="<%= path.startsWith('/requests') && !(path === '/requests/new' && typeof type !== 'undefined' && type === 'leave') ? 'active' : '' %>" href="/requests">Requests</a>
          <% if (!['manager', 'director'].includes(user.position_level)) { %><a class="<%= path === '/requests/new' && typeof type !== 'undefined' && type === 'leave' ? 'active' : '' %>" href="/requests/new?type=leave">Apply for leave</a><% } %>
        <% } %>
        <% if (user.position_level === 'supervisor') { %><a class="<%= path === '/admin/stock' ? 'active' : '' %>" href="/admin/stock">Master Database</a><% } %>
        <% if (user.role !== 'staff' && !['supervisor', 'head_technician', 'assistant_head_technician'].includes(user.position_level)) { %><a class="<%= path === '/wallet' ? 'active' : '' %>" href="/wallet">Wallet</a><% } %>
        <%# Same people as canViewFinanceReports, canViewStockReports or canViewPeopleReports in server.js. %>
        <% if (['wallet_admin', 'admin', 'super_admin'].includes(user.role) || ['admin', 'director', 'manager', 'finance_officer', 'supervisor', 'head_technician', 'assistant_head_technician'].includes(user.position_level)) { %><a class="<%= path.startsWith('/reports') ? 'active' : '' %>" href="/reports">Reports</a><% } %>
        <% if (['admin', 'super_admin'].includes(user.role) || ['director', 'manager'].includes(user.position_level)) { %><a class="<%= path === '/admin/users' ? 'active' : '' %>" href="/admin/users">Users</a><% } %>
      </nav>
      <% const unread = typeof unreadNotifications === 'number' ? unreadNotifications : 0; %>
      <a class="notification-bell<%= path === '/notifications' ? ' active' : '' %>" href="/notifications" aria-label="Notifications<%= unread ? ` (${unread} unread)` : '' %>">
        <svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path fill="currentColor" d="M12 22a2.5 2.5 0 0 0 2.45-2h-4.9A2.5 2.5 0 0 0 12 22Zm7-6V11a7 7 0 0 0-5.5-6.84V3.5a1.5 1.5 0 0 0-3 0v.66A7 7 0 0 0 5 11v5l-2 2v1h18v-1l-2-2Z"/></svg>
        <% if (unread) { %><span class="notification-count"><%= unread > 99 ? '99+' : unread %></span><% } %>
      </a>
      <div class="user-menu">
        <span class="avatar" aria-hidden="true"><%= initials(user.full_name) %></span>
        <span class="user-meta"><strong><%= user.full_name %></strong><small><%= positionLabel(user.position_level) %></small></span>
        <a class="account-link<%= path === '/account/password' ? ' active' : '' %>" href="/account/password" title="Change password" aria-label="Change password"><svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path fill="currentColor" d="M7 14a2 2 0 1 1 0-4 2 2 0 0 1 0 4Zm5.65-4A6 6 0 1 0 12.65 14H17v3h3v-3h2v-4h-9.35Z"/></svg><span>Password</span></a>
        <form method="post" action="/logout"><button class="signout" type="submit">Sign out</button></form>
      </div>
    <% } %>
  </div>
  <div class="brand-stripe" aria-hidden="true"></div>
</header>
<main class="shell" id="main">
<% if (typeof flash !== 'undefined' && flash) { %><div class="alert <%= flash.type %>" role="<%= flash.type === 'error' ? 'alert' : 'status' %>"><%= flash.text %></div><% } %>
