<div class="layout">

  <div class="main">

    <%- include("partials/page-header", {
      user,
      title: t.global.edit,
      subtitle: patient.firstname + " " + patient.lastname,
      showUserName: true,
      hideDashboardButton: false
    }) %>

    <div class="content">

      <%- include("partials/flash") %>

      <div class="container-fluid">

        <div class="card shadow mx-auto" style="max-width: 700px;">
          <div class="card-body">

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

            <form method="POST" action="/patients/update/<%= patient.id %>">

              <input type="hidden" name="returnTo" value="<%= returnTo || '' %>">

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

              <div class="row">
                <div class="col-md-4 mb-2">
                  <select class="form-select" name="gender">
                    <option value=""><%= t.global.gender %></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="<%= t.patientEdit.email %>" />
              <input class="form-control mb-2" name="phone"
                value="<%= patient.phone || '' %>"
                placeholder="<%= t.patientEdit.phone %>" />
              <input class="form-control mb-2" name="street"
                value="<%= patient.street || '' %>"
                placeholder="<%= t.patientEdit.street %>" />
              <input class="form-control mb-2" name="house_number"
                value="<%= patient.house_number || '' %>"
                placeholder="<%= t.patientEdit.housenumber %>" />
              <input class="form-control mb-2" name="postal_code"
                value="<%= patient.postal_code || '' %>"
                placeholder="<%= t.patientEdit.zip %>" />
              <input class="form-control mb-2" name="city"
                value="<%= patient.city || '' %>"
                placeholder="<%= t.patientEdit.city %>" />
              <input class="form-control mb-2" name="country"
                value="<%= patient.country || '' %>"
                placeholder="<%= t.patientEdit.country %>" />

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

              <button class="btn btn-primary w-100">
                <%= t.patientEdit.save %>
              </button>

            </form>

          </div>
        </div>

      </div>

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