{% if !further_posten_required && !further_fuehrungsassistent_required && !further_wachhabender_required %}
<div class="icon-text">
  <svg class="icon has-text-success">
    <use href="/static/feather-sprite.svg#check" />
  </svg>
  <span>Alle Plätze verplant!</span>
</div>
{% endif %}

<table class="table is-fullwidth">
  <thead>
    <tr>
      <th>Name</th>
      <th>Funktion</th>
      <th>Zeitraum</th>
      <th>Kommentar</th>
      <th>Status</th>
      <th>Planen als</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    {% for (availabillity, status) in availabillities %}
    {% let u = availabillity.user.as_ref().unwrap() %}
    <tr>
      <td>{{ u.name }}</td>
      <td>
        {{ u.function|show_tree|safe }}
      </td>
      <td>
        {% if availabillity.start_time.is_some() && availabillity.end_time.is_some() %}
        {{ availabillity.start_time.as_ref().unwrap().format("%R") }} bis {{
        availabillity.end_time.as_ref().unwrap().format("%R") }}
        {% else %}
        ganztägig
        {% endif %}
      </td>
      <td>
        {{ availabillity.comment.as_deref().unwrap_or("") }}
      </td>
      <td>
        {{ status }}
      </td>
      <td>
        <div class="buttons has-addons">
          <button hx-post="/assignments/new?event={{ event.id }}&availabillity={{ availabillity.id }}&function=1"
            hx-target="closest table" hx-swap="outerHTML" class="button is-small" {% if !further_posten_required ||
            status !=AvailabillityAssignmentState::Unassigned|ref %}disabled{% endif %}>Posten</button>
          {% if u.function == Function::Wachhabender || u.function == Function::Fuehrungsassistent %}
          <button hx-post="/assignments/new?event={{ event.id }}&availabillity={{ availabillity.id }}&function=5"
            hx-target="closest table" hx-swap="outerHTML" class="button is-small" {% if
            !further_fuehrungsassistent_required || status !=AvailabillityAssignmentState::Unassigned|ref
            %}disabled{% endif %}>Führungsassistent</button>
          {% endif %}
          {% if u.function == Function::Wachhabender %}
          <button hx-post="/assignments/new?event={{ event.id }}&availabillity={{ availabillity.id }}&function=10"
            hx-target="closest table" hx-swap="outerHTML" class="button is-small" {% if !further_wachhabender_required
            || status !=AvailabillityAssignmentState::Unassigned|ref %}disabled{% endif %}>Wachhabender</button>
          {% endif %}
        </div>
      </td>
      <td>
        {% if status != AvailabillityAssignmentState::Unassigned|ref && status !=
        AvailabillityAssignmentState::Conflicting|ref %}
        <button hx-delete="/assignments/delete?event={{ event.id }}&availabillity={{ availabillity.id }}"
          hx-target="closest table" hx-swap="outerHTML" class="button is-small">Entplanen</button>
        {% endif %}
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
