<%
  const pid = patient?.id || null;

  // ✅ Wenn wir in der Medikamentenseite sind → nur Zurück anzeigen
  const onlyBack = active === "patient_medications";
%>

<div class="sidebar">

  <!-- ✅ Logo -->
  <div style="margin-bottom: 30px; display: flex; flex-direction: column; gap: 10px;">
    <div style="padding: 20px; text-align: center">
      <div class="logo" style="margin: 0">🩺 Praxis System</div>
    </div>
  </div>

  <!-- ✅ Zurück (immer sichtbar) -->
  <a href="<%= pid ? '/patients/' + pid + '/overview' : '/dashboard' %>" class="nav-item">
    <i class="bi bi-arrow-left-circle"></i> Zurück
  </a>

  <% if (!onlyBack && pid) { %>

    <div style="margin: 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.12)"></div>

    <!-- ✅ Medikamentenverwaltung -->
    <a
      href="/patients/<%= pid %>/medications?returnTo=overview"
      class="nav-item <%= active === 'patient_medications' ? 'active' : '' %>"
    >
      <i class="bi bi-capsule"></i> Medikamentenverwaltung
    </a>

    <!-- ✅ Patient bearbeiten -->
    <a
      href="/patients/edit/<%= pid %>?returnTo=overview"
      class="nav-item <%= active === 'patient_edit' ? 'active' : '' %>"
    >
      <i class="bi bi-pencil-square"></i> Patient bearbeiten
    </a>

    <!-- ✅ Ins Wartezimmer -->
    <form method="POST" action="/patients/<%= pid %>/back-to-waiting-room">
      <button
        type="submit"
        class="nav-item"
        style="width:100%; border:none; background:transparent; text-align:left;"
      >
        <i class="bi bi-door-open"></i> Ins Wartezimmer
      </button>
    </form>

    <!-- ✅ Entlassen -->
    <form method="POST" action="/patients/<%= pid %>/discharge">
      <button
        type="submit"
        class="nav-item"
        style="width:100%; border:none; background:transparent; text-align:left;"
        onclick="return confirm('Patient wirklich entlassen?')"
      >
        <i class="bi bi-check2-circle"></i> Entlassen
      </button>
    </form>

  <% } %>

</div>
