{% extends "nav.html" %}

{% block content %}
<section class="section">
  <div class="container">
    {% if location.is_some() %}
    <form method="post" action="/locations/edit/{{ location.as_ref().unwrap().id }}">
      <h1 class="title">Veranstaltungsort '{{ location.as_ref().unwrap().name }}' bearbeiten</h1>
      {% else %}
      <form method="post" action="/locations/new">
        <h1 class="title">Neuen Ort anlegen</h1>
        {% endif %}

        <div class="field is-horizontal">
          <div class="field-label">
            <label class="label">Name</label>
          </div>
          <div class="field-body">
            <div class="field">
              <div class="control">
                <input class="input" type="text" name="name" required placeholder="Zentralstadion" {% if
                  location.is_some() -%} value="{{ location.as_ref().unwrap().name }}" {% endif -%} />
              </div>
            </div>
          </div>
        </div>

        {% if user.role == Role::Admin %}
        <div class="field is-horizontal">
          <div class="field-label">
            <label class="label">Bereich</label>
          </div>
          <div class="field-body">
            <div class="field is-narrow">
              <div class="control">
                <div class="select is-fullwidth">
                  <select required name="area">
                    {%- let areaid = None %}
                    {% if let Some(loc) = location %}
                    {% let areaid = loc.area_id %}
                    {% endif -%}
                    {% for area in areas.as_ref().unwrap() %}
                    <option {{ areaid|is_some_and_eq(area.id)|ref|cond_show("selected") }} value="{{ area.id }}">{{
                      area.name }}</option>
                    {% endfor %}
                  </select>
                </div>
              </div>
            </div>
          </div>
        </div>
        {% endif %}

        <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 location.is_some() %}
                    Speichern
                    {% else %}
                    Erstellen
                    {% endif %}
                  </span>
                </button>
              </div>
              <div class="control">
                <a class="button is-link is-light" hx-boost="true" href="/locations">
                  <svg class="icon">
                    <use href="/static/feather-sprite.svg#arrow-left" />
                  </svg>
                  <span>Zurück</span>
                </a>
              </div>
            </div>
          </div>
        </div>

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

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