{% extends "nav.html" %}

{% block content %}
<section class="section">
  <div class="container">
    {% if id.is_some() %}
    <form method="post" action="/availabillity/edit/{{ id.unwrap() }}">
      <h1 class="title">Bearbeite Vefügbarkeit für den {{ date.format("%d.%m.%Y") }}</h1>
      {% else %}
      <form method="post" action="/availabillity/new">
        <h1 class="title">Neue Vefügbarkeit für den {{ date.format("%d.%m.%Y") }}</h1>
        {% endif %}

        <input type="hidden" name="date" value="{{ date }}">

        <div class="field is-horizontal">
          <div class="field-label">
            <label class="label">Dauer</label>
          </div>
          <div class="field-body">
            <div class="field">
              <div class="control">
                <label class="radio">
                  {% if id.is_some() %}
                  <input type="radio" name="hasTime" hx-get="/availabillity/edit/{{ id.unwrap() }}?wholeday=true"
                    hx-target="closest body" {{ whole_day|cond_show("checked") }} />
                  {% else %}
                  <input type="radio" name="hasTime" hx-get="/availabillity/new?date={{ date }}&wholeday=true"
                    hx-target="closest body" {{ whole_day|cond_show("checked") }} />
                  {% endif %}
                  ganztägig
                  <label class="radio">
                    {% if id.is_some() %}
                    <input type="radio" name="hasTime" hx-get="/availabillity/edit/{{ id.unwrap() }}?wholeday=false"
                      hx-target="closest body" {{ whole_day|invert|ref|cond_show("checked") }} />
                    {% else %}
                    <input type="radio" name="hasTime" hx-get="/availabillity/new?date={{ date }}&wholeday=false"
                      hx-target="closest body" {{ whole_day|invert|ref|cond_show("checked") }} />
                    {% endif %}
                    zeitweise
                  </label>
              </div>
            </div>
          </div>
        </div>

        <div class="field is-horizontal">
          <div class="field-label">
            <label class="label">Von - Bis</label>
          </div>
          <div class="field-body">
            <div class="field">
              <input class="input" type="time" id="from" name="from" value='{{ start_time.unwrap_or("00:00") }}' {{
                whole_day|cond_show("disabled") }} {{ whole_day|invert|ref|cond_show("required") }}>
            </div>
            <div class="field">
              <input class="input" type="time" id="till" name="till" value='{{ end_time.unwrap_or("23:59") }}' {{
                whole_day|cond_show("disabled") }} {{ whole_day|invert|ref|cond_show("required") }}>
            </div>
          </div>
        </div>

        <div class="field is-horizontal">
          <div class="field-label">
            <label class="label">Kommentar</label>
          </div>
          <div class="field-body">
            <div class="field">
              <div class="control">
                <textarea class="textarea" name="comment" placeholder="nur Posten, nur Wachhabender, etc..">{{
                  comment.unwrap_or("") }}</textarea>
              </div>
            </div>
          </div>
        </div>

        <div class="field is-horizontal">
          <div class="field-label"></div>
          <div class="field-body">
            <div class="field is-grouped">
              <div class="control">
                <button class="button is-success">
                  <svg class="icon">
                    <use href="/static/feather-sprite.svg#check-circle" />
                  </svg>
                  <span>
                    {% if id.is_some() %}
                    Speichern
                    {% else %}
                    Erstellen
                    {% endif %}
                  </span>
                </button>
              </div>
              <div class="control">
                <a class="button is-link is-light" hx-boost="true" href="/?date={{ date }}">
                  <svg class="icon">
                    <use href="/static/feather-sprite.svg#arrow-left" />
                  </svg>
                  <span>Zurück</span>
                </a>
              </div>
            </div>
          </div>
        </div>

      </form>
  </div>
</section>
{% endblock %}
