<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Patient bearbeiten</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">Patient bearbeiten</span>
    <a href="<%= returnTo === 'overview'
            ? `/patients/${patient.id}/overview`
            : '/patients' %>" class="btn btn-outline-light btn-sm">
        Zurück
    </a>
</nav>

<div class="container mt-4">
    <%- include("partials/flash") %>
    <div class="card shadow mx-auto" style="max-width: 700px;">
        <div class="card-body">

            <h4 class="mb-3">
                <%= patient.firstname %> <%= patient.lastname %>
            </h4>

            <% if (error) { %>
                <div class="alert alert-danger"><%= error %></div>
            <% } %>

            <form method="POST" action="/patients/edit/<%= patient.id %>?returnTo=<%= returnTo || '' %>">

                <div class="row">
                    <div class="col-md-6 mb-2">
                        <input class="form-control"
                               name="firstname"
                               value="<%= patient.firstname %>"
                               placeholder="Vorname"
                               required>
                    </div>

                    <div class="col-md-6 mb-2">
                        <input class="form-control"
                               name="lastname"
                               value="<%= patient.lastname %>"
                               placeholder="Nachname"
                               required>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-4 mb-2">
                        <select class="form-select" name="gender">
                            <option value="">Geschlecht</option>
                            <option value="m" <%= patient.gender === 'm' ? 'selected' : '' %>>Männlich</option>
                            <option value="w" <%= patient.gender === 'w' ? 'selected' : '' %>>Weiblich</option>
                            <option value="d" <%= patient.gender === 'd' ? 'selected' : '' %>>Divers</option>
                        </select>
                    </div>

                    <div class="col-md-8 mb-2">
                        <input class="form-control"
                               type="date"
                               name="birthdate"
                               value="<%= patient.birthdate ? new Date(patient.birthdate).toISOString().split('T')[0] : '' %>"
                               required>
                    </div>
                </div>

                <input class="form-control mb-2" name="email" value="<%= patient.email || '' %>" placeholder="E-Mail">
                <input class="form-control mb-2" name="phone" value="<%= patient.phone || '' %>" placeholder="Telefon">

                <input class="form-control mb-2" name="street" value="<%= patient.street || '' %>" placeholder="Straße">
                <input class="form-control mb-2" name="house_number" value="<%= patient.house_number || '' %>" placeholder="Hausnummer">
                <input class="form-control mb-2" name="postal_code" value="<%= patient.postal_code || '' %>" placeholder="PLZ">
                <input class="form-control mb-2" name="city" value="<%= patient.city || '' %>" placeholder="Ort">
                <input class="form-control mb-2" name="country" value="<%= patient.country || '' %>" placeholder="Land">

                <textarea class="form-control mb-3"
                          name="notes"
                          rows="4"
                          placeholder="Notizen"><%= patient.notes || '' %></textarea>

                <button class="btn btn-primary w-100">
                    Änderungen speichern
                </button>
            </form>

        </div>
    </div>
</div>

</body>
</html>
