{% extends "base.html" %}
{% load wagtailcore_tags wagtailsettings_tags gem_tags %}
{% wagtail_site as current_site %}
{% get_settings %}
{% block content %}
<div class="profiles">
    {% trans "Hello" as headingtext %}
    {% if user.profile.alias %}
        {% with user.profile.alias as alias %}

            {# include template "patterns/basics/headings/sp_variations/heading.html" #}
              {% with type="component" htmltag="h1" title=headingtext|add:" "|add:alias %}
                <div class="heading heading__{{type}} {{extraclass}}">
                  <{{htmltag}}>{{title}}</{{htmltag}}>
                </div>
              {% endwith %}
            {# end include template #}

        {% endwith %}
    {% else %}
        {% with user|stringformat:"s" as username %}

            {# include template "patterns/basics/headings/sp_variations/heading.html" #}
              {% with type="component" htmltag="h1" title=headingtext|add:" "|add:user.profile.migrated_username|default:username %}
                <div class="heading heading__{{type}} {{extraclass}}">
                  <{{htmltag}}>{{title}}</{{htmltag}}>
                </div>
              {% endwith %}
            {# end include template #}

        {% endwith %}
    {% endif %}

    <form method="post" action="{{ LOGOUT_URL }}">
      {% csrf_token %}
      <button class="call-to-action__button call-to-action__button-text call-to-action__button-text--hyperlink" type="submit">{% trans "Log out" %}</button>
    </form>

    {# include template "patterns/basics/headings/sp_variations/heading.html" #}
      {% trans "Your Profile" as headingtext %}
      {% with type="basic" htmltag="h2" title=headingtext %}
        <div class="heading heading__{{type}} {{extraclass}}">
          <{{htmltag}}>{{title}}</{{htmltag}}>
        </div>
      {% endwith %}
    {# end include template #}

    {% trans "Not set." as defaultText %}
    {% with profile_settings=settings.profiles.UserProfilesSettings %}
    {% if profile_settings.activate_display_name %}
      <fieldset>
          {% if user.profile.alias %}
              <label>{% trans "When you type comments your name will appear as:" %}
                  <span class="input-feedback">{{ user.profile.alias }}</span>
              </label>
          {% else %}
              <label>{% trans "You haven't set a display name, so your comments will appear as 'anonymous'" %}</label>
          {% endif %}
      </fieldset>
    {% endif %}

    {% if profile_settings.activate_dob %}
    <fieldset>
        <label>{% trans "Date of Birth: " %}</label>
        <span class="input-feedback">
            {{ user.profile.date_of_birth|default:defaultText }}
        </span>
    </fieldset>
    {% endif %}

    {% if profile_settings.activate_gender%}
    <fieldset>
        <label>{% trans "Gender:" %}</label>
        <span class="input-feedback">{{user.profile.gender|gender_display|default:defaultText }}</span>
    </fieldset>
    {% endif %}

    {% if profile_settings.activate_education_level %}
    <fieldset>
        <label>{% trans "Education Level:" %}</label>
        <span class="input-feedback">{{ user.profile.education_level|default:defaultText }}</span>
    </fieldset>
    {% endif %}
    {% endwith %}

    {# include template "patterns/basics/buttons/sp_variations/button.html" #}
      {% trans "Update Profile" as buttontext %}
      {% with type="primary" text=buttontext %}
        <a href="{{EDIT_PROFILE_URL}}" class="call-to-action__button call-to-action__button--{{type}}">
          <span class="call-to-action__button-text call-to-action__button-text--{{type}}">{{text}}</span>
        </a>
      {% endwith %}
    {# end include template #}

    <form method="post" id="frmProfilePasswordChange" action="{% url 'molo.profiles:profile_password_change' %}" class="profiles__form profiles__form--block" novalidate>
    {% csrf_token %}

        {# include template "patterns/basics/headings/sp_variations/heading.html" #}
          {% trans "Change Your Pin" as headingtext %}
          {% with type="basic" htmltag="h2" title=headingtext %}
            <div class="heading heading__{{type}} {{extraclass}}">
              <{{htmltag}}>{{title}}</{{htmltag}}>
            </div>
          {% endwith %}
        {# end include template #}

        {% if form.errors or form.non_field_errors %}
            {% if form.non_field_errors %}
                {% for error in form.non_field_errors %}
                    <p class="errors">{{ error }}</p>
                {% endfor %}
            {% endif %}
        {% endif %}

        <fieldset>
            <label>{% trans "Old Pin:" %}</label>
            {{ password_change_form.old_password }}
            {{ password_change_form.old_password.errors }}
        </fieldset>
        <fieldset>
            <label>{% trans "New Pin:" %}</label>
            {{ password_change_form.new_password }}
            {{ form.new_password.errors }}
        </fieldset>
        <fieldset>
            <label>{% trans "Confirm Pin:" %}</label>
            {{ password_change_form.confirm_password }}
            {{ form.confirm_password.errors }}
        </fieldset>
        <button type="submit" class="call-to-action__button call-to-action__button--primary">{% trans "Change" %}</button>
    </form>
    <a href="{{current_site.root_page.url}}" class="call-to-action__nav-item-text call-to-action__nav-item-text--left">{% trans "Homepage" %}</a>
</div>
{% endblock %}
