{% extends theme('base.html') %}
{% import 'macro/form.html' as fui %}
{% import 'macro/profile.html' as profile %}

{%- block title -%}
    {% if not edited_user %}
        {%- trans %}User creation{% endtrans -%}
    {% elif user.user_name == edited_user.user_name %}
        {%- trans %}My profile{% endtrans -%}
    {% else %}
        {%- trans %}User profile edition{% endtrans -%}
    {% endif %}
{%- endblock -%}

{% block script %}
    <script src="/static/js/profile.js" defer></script>
{% endblock %}

{% block submenu %}
    <nav class="ui bottom attached two item borderless menu">
        <a class="active item" href="{{ url_for('account.profile_edition', edited_user=edited_user) }}">
            <i class="id card icon"></i>
            {% trans %}Personal information{% endtrans %}
        </a>
        <a class="item" href="{{ url_for('account.profile_settings', edited_user=edited_user) }}">
            <i class="tools icon"></i>
            {% trans %}Account information{% endtrans %}
        </a>
    </nav>
{% endblock %}

{% block content %}
    <div class="ui clearing segment">
        <h2 class="ui center aligned header">
            <div class="content">
                {% if user.user_name == edited_user.user_name %}
                    {% trans %}My profile{% endtrans %}
                {% else %}
                    {% trans %}User profile edition{% endtrans %}
                {% endif %}

            </div>
            <div class="sub header">
                {% if user.user_name == edited_user.user_name %}
                    {% trans %}Edit your personal information{% endtrans %}
                {% else %}
                    {% trans %}Edit information about a user{% endtrans %}
                {% endif %}
            </div>
        </h2>

        {% call fui.render_form(form) %}
            {% if "photo" in form %}
                <div class="ui grid">
                    <div class="three wide column">
                        {% block photo_field scoped %}
                            {{ profile.render_field(form.photo, display=false, class="photo-field") }}
                            {{ profile.render_field(form.photo_delete, display=false, class="photo-delete-button") }}
                            {% set photo = edited_user.photo and edited_user.photo[0] %}
                            <label
                                class="ui small bordered image photo-content"
                                for="{{ form.photo.id }}"
                                title="{{ _("Click to upload a photo") }}"
                                {% if not photo %}style="display: none;"{% endif %}>

                                <a class="ui right corner label photo-delete-icon" title="{{ _("Delete the photo") }}">
                                    <i class="times icon"></i>
                                </a>
                                <img src="{% if photo %}{{ url_for("account.photo", user=edited_user, field="photo") }}{% endif %}" alt="User photo">
                            </label>
                            <label
                                class="ui centered photo-placeholder"
                                for="{{ form.photo.id }}"
                                title="{{ _("Click to upload a photo") }}"
                                {% if photo %}style="display: none;"{% endif %}>
                                <i class="massive centered portrait icon"></i>
                            </label>
                            </div>
                        {% endblock %}

                        <div class="thirteen wide column">
            {% endif %}

            {% if "given_name" in form or "family_name" in form %}
                <div class="equal width fields">
                    {% if "given_name" in form %}
                        {% block given_name_field scoped %}{{ profile.render_field(form.given_name, user, edited_user) }}{% endblock %}
                    {% endif %}

                    {% if "family_name" in form %}
                        {% block sn_field scoped %}{{ profile.render_field(form.family_name, user, edited_user) }}{% endblock %}
                    {% endif %}
                </div>
            {% endif %}

            {% if "display_name" in form %}
                {% block display_name_field scoped %}{{ profile.render_field(form.display_name, user, edited_user) }}{% endblock %}
            {% endif %}

            {% if "photo" in form %}</div></div>{% endif %}

            {% if "emails" in form %}
                {% block emails_field scoped %}{{ profile.render_field(form.emails, user, edited_user) }}{% endblock %}
            {% endif %}

            {% if "phone_numbers" in form %}
                {% block phone_numbers_field scoped %}{{ profile.render_field(form.phone_numbers, user, edited_user) }}{% endblock %}
            {% endif %}

            {% if "formatted_address" in form %}
                {% block formatted_address_field scoped %}{{ profile.render_field(form.formatted_address, user, edited_user) }}{% endblock %}
            {% endif %}

            {% if "street" in form %}
                {% block street_field scoped %}{{ profile.render_field(form.street, user, edited_user) }}{% endblock %}
            {% endif %}

            <div class="equal width fields">
                {% if "postal_code" in form %}
                    {% block postal_code_field scoped %}{{ profile.render_field(form.postal_code, user, edited_user) }}{% endblock %}
                {% endif %}

                {% if "locality" in form %}
                    {% block locality_field scoped %}{{ profile.render_field(form.locality, user, edited_user) }}{% endblock %}
                {% endif %}

                {% if "region" in form %}
                    {% block region_field scoped %}{{ profile.render_field(form.region, user, edited_user) }}{% endblock %}
                {% endif %}
            </div>

            <div class="equal width fields">

                {% if "department" in form %}
                    {% block department_number_field scoped %}{{ profile.render_field(form.department, user, edited_user) }}{% endblock %}
                {% endif %}

                {% if "employee_number" in form %}
                    {% block employee_number_field scoped %}{{ profile.render_field(form.employee_number, user, edited_user) }}{% endblock %}
                {% endif %}
            </div>

            <div class="equal width fields">

                {% if "title" in form %}
                    {% block title_field scoped %}{{ profile.render_field(form.title, user, edited_user) }}{% endblock %}
                {% endif %}

                {% if "organization" in form %}
                    {% block organization_field scoped %}{{ profile.render_field(form.organization, user, edited_user) }}{% endblock %}
                {% endif %}

            </div>

            {% if "profile_url" in form %}
                {% block profile_url_field scoped %}{{ profile.render_field(form.profile_url, user, edited_user) }}{% endblock %}
            {% endif %}

            {% if "preferred_language" in form %}
                {% block preferred_language_field scoped %}{{ profile.render_field(form.preferred_language, user, edited_user) }}{% endblock %}
            {% endif %}

            <div class="ui right aligned container">
                <div class="ui stackable buttons">
                    <button type="submit" class="ui right floated primary button" name="action" value="edit" id="edit">
                        {{ _("Edit") }}
                    </button>
                </div>
            </div>
        {% endcall %}
    </div>
{% endblock %}
