{% extends "nav.html" %}

{% block content %}
<section class="section">
  <div class="container">
    <form method="post" action="/assignments/new">
      <input type="hidden" name="event" value="{{ event.id }}" />

      <h1 class="title">Planung für {{ event.name }}</h1>
      <div class="box">
        {% if event.canceled %}<b>Veranstaltung abgesagt!</b>{% endif %}
        <p>Ort: {{ event.location.as_ref().unwrap().name }}</p>
        <p>Zeitraum: {{ event.start_time }} bis {{ event.end_time }}</p>
        <p>Anzahl der Posten: {{ event.amount_of_posten }}</p>
        <p>Wachhabender durch FF gestellt: {{ event.voluntary_wachhabender }}</p>
        <p>Kleidungsordnung: {{ event.clothing }}</p>
      </div>

      <div class="box">
        <table class="table is-fullwidth">
          <thead>
            <tr>
              <th>Name</th>
              <th>Funktion</th>
              <th>Zeit</th>
              <th>Kommentar</th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            {% for a in all %}
            {% let u = a.user.as_ref().unwrap() %}
            <tr>
              <td>{{ u.name }}</td>
              <td>
                {% match user.function %}
                {% when Function::Posten %}
                <span class="tag is-info">Posten</span>
                {% when Function::Wachhabender %}
                <span class="tag is-info">Wachhabender</span>
                {% else %}
                {% endmatch %}
              </td>
              <td>
                {% if a.start_time.is_some() && a.end_time.is_some() %}
                {{ a.start_time.as_ref().unwrap() }} - {{ a.end_time.as_ref().unwrap() }}
                {% else %}
                ganztägig
                {% endif %}
              </td>
              <td>
                {{ a.comment.as_deref().unwrap_or("") }}
              </td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>

      {% if event.voluntary_wachhabender %}
      <div class="field">
        <label class="label">Wachhabender</label>
        <div class="select">
          <select name="wachhabender">
            {% for a in available_wachhabende %}
            {% let user = a.user.as_ref().unwrap() %}
            <option value="{{ a.id }}">
              {{ user.name }} -
              {% match user.function %}
              {% when Function::Posten %}
              Posten
              {% when Function::Wachhabender %}
              Wachhabender
              {% else %}
              {% endmatch %}
              -
              {% if a.start_time.is_some() && a.end_time.is_some() %}
              {{ a.start_time.as_ref().unwrap() }} - {{ a.end_time.as_ref().unwrap() }}
              {% else %}
              ganztägig
              {% endif %}
            </option>
            {% endfor %}
          </select>
        </div>
      </div>
      {% endif %}

      <div class="field">
        <label class="label">Posten</label>
        <p class="help">Mehrfachauswahl mit Strg+Mausklick</p>
        <div class="select is-multiple">
          <select name="posten" multiple size="{{ available_posten.len() }}">
            {% for a in available_posten %}
            {% let user = a.user.as_ref().unwrap() %}
            <option value="{{ a.id }}">
              {{ user.name }} -
              {% match user.function %}
              {% when Function::Posten %}
              Posten
              {% when Function::Wachhabender %}
              Wachhabender
              {% else %}
              {% endmatch %}
              -
              {% if a.start_time.is_some() && a.end_time.is_some() %}
              {{ a.start_time.as_ref().unwrap() }} - {{ a.end_time.as_ref().unwrap() }}
              {% else %}
              ganztägig
              {% endif %}
            </option>
            {% endfor %}
          </select>
        </div>
      </div>

      <div class="field">
        <label class="label">Fahrzeug</label>
        <div class="select">
          <select>
            <option>Fahrzeug</option>
          </select>
        </div>
      </div>

      <div class="field is-horizontal">
        <div class="field-label"></div>
        <div class="field-body">
          <div class="field is-grouped">
            <div class="control">
              <input class="button is-link" type="submit" value="Erstellen">
            </div>
            <div class="control">
              <a class="button is-link is-light" href="/">Zurück</a>
            </div>
          </div>
        </div>
      </div>

    </form>
  </div>
</section>

<script>
</script>
{% endblock %}
