{% extends "nav.html" %}

{% block content %}
<section class="section">
  <div class="container">
    <h1 class="title">Profil</h1>

    <section class="section">
      <h5 class="title is-5">Allgemeines</h5>

      <div class="field is-horizontal">
        <div class="field-label is-normal">
          <label class="label">Name</label>
        </div>
        <div class="field-body">
          <div class="field">
            <div class="control">
              <input class="input is-static" type="text" value="{{ user.name }}" readonly>
            </div>
          </div>
        </div>
      </div>

      <div class="field is-horizontal">
        <div class="field-label is-normal">
          <label class="label">E-Mail</label>
        </div>
        <div class="field-body">
          <div class="field">
            <div class="control">
              <input class="input is-static" type="email" value="{{ user.email }}" readonly>
            </div>
          </div>
        </div>
      </div>

      <div class="field is-horizontal">
        <div class="field-label is-normal">
          <label class="label">Rolle</label>
        </div>
        <div class="field-body">
          <div class="field">
            <div class="control">
              {% match user.role %}
              {% when Role::Staff %}
              <span class="tag is-info is-light">Personal</span>
              {% when Role::AreaManager %}
              <span class="tag is-info is-light">Bereichsleiter</span>
              {% when Role::Admin %}
              <span class="tag is-info">Admin</span>
              {% else %}
              {% endmatch %}
            </div>
          </div>
        </div>
      </div>

      <div class="field is-horizontal">
        <div class="field-label is-normal">
          <label class="label">Funktion</label>
        </div>
        <div class="field-body">
          <div class="field">
            <div class="control">
                {{ user.function|show_tree|safe }}
            </div>
          </div>
        </div>
      </div>

      <div class="field is-horizontal">
        <div class="field-label is-normal">
          <label class="label">Bereich</label>
        </div>
        <div class="field-body">
          <div class="field">
            <div class="control">
              <input class="input is-static" type="text" value="{{ user.area.as_ref().unwrap().name }}" readonly>
            </div>
          </div>
        </div>
      </div>
    </section>

    <section class="section">
      <h5 class="title is-5">Benachrichtigungen</h5>

      <div class="field">
        <div class="control">
          <label class="checkbox">
            <input hx-post="/users/{{ user.id }}/toggle?field=receiveNotifications" type="checkbox"
              hx-on::before-request="document.getElementById('success').classList.remove('fadeout')"
              hx-on::after-request="document.getElementById('success').classList.add('fadeout')"
              checked="{{ user.receive_notifications }}">
            Ich möchte E-Mail Benachrichtigungen zu neuen Brasiwa-Einteilungen erhalten.
            <span id="success" class="result">
              <svg class="icon mr-2">
                <use href="/static/feather-sprite.svg#check" />
              </svg>
              <span>
                gespeichert
              </span>
            </span>
          </label>
        </div>
      </div>
    </section>

    <section class="section">
      <h5 class="title is-5">Passwort</h5>

      <div class="field">
        <div class="control">
          <button hx-get="/users/changepassword" hx-target="closest div.field" hx-swap="outerHTML"
            class="button is-link is-light">Passwort ändern</button>
        </div>
      </div>
    </section>

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