<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Medikationsplan – <%= patient.firstname %> <%= patient.lastname %></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body class="bg-light">

<nav class="navbar navbar-dark bg-dark px-3">
    <span class="navbar-brand">
        📄 Medikationsplan – <%= patient.firstname %> <%= patient.lastname %>
    </span>
    <a href="/patients/<%= patient.id %>/overview"
       class="btn btn-outline-light btn-sm">
        Zurück
    </a>
</nav>

<div class="container mt-4">
    <%- include("partials/flash") %>
    <div class="card shadow">
        <div class="card-body">

            <table class="table table-bordered table-sm">
                <thead class="table-light">
                    <tr>
                        <th>Medikament</th>
                        <th>Form</th>
                        <th>Dosierung</th>
                        <th>Packung</th>
                        <th>Anweisung</th>
                        <th>Zeitraum</th>
                    </tr>
                </thead>

                <tbody>
                <% if (meds.length === 0) { %>
                    <tr>
                        <td colspan="6" class="text-center text-muted">
                            Keine aktuelle Medikation
                        </td>
                    </tr>
                <% } %>

                <% meds.forEach(m => { %>
                    <tr>
                        <td><%= m.medication %></td>
                        <td><%= m.form %></td>
                        <td><%= m.dosage %></td>
                        <td><%= m.package %></td>
                        <td><%= m.dosage_instruction || "-" %></td>
                        <td>
                            <%= m.start_date
                                ? new Date(m.start_date).toLocaleDateString("de-DE")
                                : "-" %>
                            –
                            <%= m.end_date
                                ? new Date(m.end_date).toLocaleDateString("de-DE")
                                : "laufend" %>
                        </td>
                    </tr>
                <% }) %>
                </tbody>
            </table>

        </div>
    </div>

</div>

</body>
</html>
