<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Wartezimmer</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
     <link rel="stylesheet" href="/bootstrap-icons/bootstrap-icons.min.css">
</head>
<body>

<nav class="navbar navbar-dark bg-dark position-relative px-3">

    <!-- 🟢 ZENTRIERTER TITEL -->
    <div class="position-absolute top-50 start-50 translate-middle
                d-flex align-items-center gap-2 text-white">
        <span style="font-size:1.4rem;">🪑</span>
        <span class="fw-semibold fs-5">Wartezimmer</span>
    </div>

    <!-- 🔵 RECHTS: DASHBOARD -->
    <div class="ms-auto">
        <a href="/dashboard" class="btn btn-outline-primary btn-sm">
            ⬅️ Dashboard
        </a>
    </div>

</nav>


<div class="container mt-4">

    <!-- ✅ EINMAL Flash anzeigen -->
    <%- include("partials/flash") %>

    <% if (patients.length === 0) { %>
        <div class="alert alert-info">
            Keine Patienten im Wartezimmer
        </div>
    <% } else { %>

        <table class="table table-bordered table-hover">
            <thead class="table-light">
                <tr>
                    <th>Name</th>
                    <th>Geburtstag</th>
                    <th>Aktion</th>
                </tr>
            </thead>
            <tbody>

            <% patients.forEach(p => { %>
                <tr>
                    <td><strong><%= p.firstname %> <%= p.lastname %></strong></td>
                    <td><%= new Date(p.birthdate).toLocaleDateString("de-DE") %></td>
                    <td>
                        <% if (user.role === 'arzt') { %>
                            <form method="POST"
                                  action="patients/waiting-room/call/<%= p.id %>"
                                  class="d-inline">
                                <button class="btn btn-sm btn-success">
                                    ▶️ Aufrufen
                                </button>
                            </form>
                        <% } else { %>
                            <span class="text-muted">🔒 Nur Arzt</span>
                        <% } %>
                    </td>
                </tr>
            <% }) %>

            </tbody>
        </table>

    <% } %>

</div>

</body>
</html>
