<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{template}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<title>Camp Organizer Confirmation</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
  <th:block layout:fragment="content">
    <div class="mainpage">
      <div class="container" style="max-width: 100%" sec:authorize="hasRole('registrator')">
        <form id="form" action="#" th:action="@{/confirmation/person/update}" th:object="${person}" method="post" th:if="${person != null}">
          <div class="row mb-2">
            <label for="outputPk" class="col-sm-2 col-form-label">ID</label>
            <div class="col-sm-10">
              <input type="text" th:field="*{pk}" class="outputPk form-control locked" />
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputForename" class="col-sm-2 col-form-label">Vorname</label>
            <div class="col-sm-4">
              <input type="text" th:field="*{forename}" class="inputForename form-control" />
            </div>
            <label for="inputSurname" class="col-sm-2 col-form-label">Nachname</label>
            <div class="col-sm-4">
              <input type="text" th:field="*{surname}" class="inputSurname form-control" />
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputStreet" class="col-sm-2 col-form-label">Straße</label>
            <div class="col-sm-10">
              <input type="text" th:field="*{street}" class="inputStreet form-control" />
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputZip" class="col-sm-2 col-form-label">PLZ</label>
            <div class="col-sm-2">
              <input type="text" th:field="*{zip}" class="inputZip form-control" />
            </div>
            <label for="inputCity" class="col-sm-2 col-form-label">Ort</label>
            <div class="col-sm-6">
              <input type="text" th:field="*{city}" class="inputCity form-control" />
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputBirthdate" class="col-sm-2 col-form-label">Geburtstag</label>
            <div class="col-sm-4">
            	<span class="error" th:each="error : ${#fields.errors('birthdate')}">[[${error}]]<br /></span>
              <input type="date" th:field="*{birthdate}" class="inputBirthdate form-control" />
            </div>
            <label for="inputSex" class="col-sm-2 col-form-label">Geschlecht</label>
            <div class="col-sm-4">
              <select class="form-select" th:field="*{sex}">
                <option value="male">männlich</option>
                <option value="female">weiblich</option>
              </select>
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputPhone" class="col-sm-2 col-form-label">Telefon</label>
            <div class="col-sm-4">
              <input type="text" th:field="*{phone}" class="inputPhone form-control" />
            </div>
            <label for="inputEmail" class="col-sm-2 col-form-label">E-Mail</label>
            <div class="col-sm-4">
            	<div class="input-group">
              	<input type="email" th:field="*{email}" class="inputEmail form-control" />
              	<a class="btn btn-outline-secondary" th:href="'mailto:' + *{email}"><i class="fas fa-envelope-square"></i></a>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <label for="outputCamp" class="col-sm-2 col-form-label">Freizeit</label>
            <div class="col-sm-10">
              <select class="form-select locked" th:field="*{fkCamp}" disabled="disabled">
                <option th:each="c : ${camps}" th:value="${c.pk}" th:text="${c.name} + ' ' + ${#temporals.format(c.arrive, 'yyyy')} + ' in ' + ${c.location}"></option>
              </select>
            </div>
          </div>
          <div class="row mb-2">
            <label for="outputCamprole" class="col-sm-2 col-form-label">Rolle</label>
            <div class="col-sm-10">
              <select class="outputCamprole form-select" th:field="*{camprole}">
                <option value="student">Teilnehmer</option>
                <option value="teacher">Mitarbeiter</option>
                <option value="director">Leiter</option>
                <option value="feeder">Küchenteam</option>
								<option value="observer">Mitarbeiterkind</option>
              </select>
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputComment" class="col-sm-2 col-form-label">Kommentar</label>
            <div class="col-sm-10">
              <textarea th:field="*{comment}" class="inputComment form-control"></textarea>
            </div>
          </div>
          <div class="row mb-2">
          	<label for="inputRequiredPrice" class="col-sm-2 col-form-label">individueller Preis</label>
          	<div class="col-sm-5">
            	<span class="error" th:each="error : ${#fields.errors('requiredPrice')}">[[${error}]]<br /></span>
          		<input type="number" th:field="*{requiredPrice}" class="inputRequiredPrice form-control" />
          	</div>
          	<div class="col-sm-5 d-flex align-items-center">
          		von offiziell&nbsp;<span th:utext="${campPrice}"></span>
          	</div>
          </div>
          <div class="row mb-2">
            <label for="outputAnno" class="col-sm-2 col-form-label">Anmerkungen</label>
            <div class="col-sm-10">
              <pre class="form-control locked" th:text="${annotations}"></pre>
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputAccept" class="col-sm-2 col-form-label">Status</label>
            <span class="col-sm-2 btn btn-outline-warning" th:if="${person.progress} == 'requested'">offen</span>
            <span class="col-sm-2 btn btn-outline-success" th:if="${person.progress} == 'approved'">bestätigt</span>
            <span class="col-sm-2 btn btn-outline-danger" th:if="${person.progress} == 'rejected'">abgelehnt</span>
            <span class="col-sm-2 btn btn-outline-secondary" th:if="${person.progress} == 'revoked'">storniert</span>
            <div class="col-sm-8" th:if="${#lists.contains({'requested', 'approved', 'rejected'}, person.progress)}">
              <select th:field="*{progress}" class="form-select">
              	<option value="requested">offen</option>
              	<option value="approved">bestätigt</option>
              	<option value="rejected">abgelehnt</option>
              </select>
            </div>
            <div class="col-sm-8" th:if="${person.progress} == 'revoked'">
              <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
  							<i class="fas fa-trash"></i>&nbsp;endgültig löschen
							</button>
            </div>
          </div>
          <div class="row mb-2">
            <label for="inputAccept" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
              <button type="submit" class="btn btn-primary" onclick="progress.start()" th:if="${person.progress} != 'revoked'">Ok</button>
              <a th:href="@{/confirmation}" class="btn btn-secondary">Abbrechen</a>
            </div>
          </div>
        </form>
				<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
				  <div class="modal-dialog">
				    <div class="modal-content">
				      <div class="modal-header bg-danger">
				        <h1 class="modal-title fs-5" id="deleteModalLabel">Löschen der Anmeldung</h1>
				        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
				      </div>
				      <div class="modal-body">
				        Willst du wirklich die Anmeldung von <span th:text="${person.forename}" class="text-danger"></span>&nbsp;<span th:text="${person.surname}" class="text-danger"></span> an der Freizeit
				        <select class="form-select locked" th:field="${person.fkCamp}" disabled="disabled">
             				<option th:each="c : ${camps}" th:value="${c.pk}" th:text="${c.name} + ' ' + ${#temporals.format(c.arrive, 'yyyy')} + ' in ' + ${c.location}"></option>
           				</select> löschen? Sie geht damit unwiederbringlich verloren.
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Abbrechen</button>
				        <a th:href="@{/registration/remove/{id}(id=${person.pk})}" class="btn btn-danger">ja, wirklich löschen</a>
				      </div>
				    </div>
				  </div>
				</div>
        <div th:if="${person == null}" class="error">In der Datenbank wurde keine Person mit entsprechender ID gefunden.</div>
      </div>
    </div>
		<script type="text/javascript">
		  /**
		   * forbid enter in form to allow disabling the ok button for revoked bookings
		   */
			$(document).on('keyup keypress', 'form', function(e) {
				if (e.keyCode == 13) {
					e.preventDefault();
					return false;
				}
			});
		</script>
	</th:block>
</body>
</html>
