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

{%- block title -%}
    {%- trans %}User creation{% endtrans -%}
{%- endblock -%}

{% block script %}
    <script src="{{ url_for("static", filename="js/profile.js") }}" defer></script>
{% endblock %}

{% block submenu %}
    <a class="item" href="{{ url_for('core.account.users') }}">
        <i class="th list icon"></i>
        {% trans %}View{% endtrans %}
    </a>
    <a class="active item" href="{{ url_for('core.account.profile_creation') }}">
        <i class="plus icon"></i>
        {% trans %}Add{% endtrans %}
    </a>
    {% if features.has_smtp %}
        <a class="item" href="{{ url_for('core.account.user_invitation') }}">
            <i class="paper plane icon"></i>
            {% trans %}Invite{% endtrans %}
        </a>
    {% endif %}
{% endblock %}

{% block content %}
    <div class="ui clearing segment">
        <h2 class="ui center aligned header">
            <div class="content">
                {% trans %}User creation{% endtrans %}
            </div>
            <div class="sub header">
                {% trans %}Create a new user account{% endtrans %}
            </div>
        </h2>

        {% call fui.render_form(form, class_="profile-form info") %}
            <h4 class="ui dividing header">{% trans %}Personal information{% endtrans %}</h4>

            {% 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") }}
                            <label
                                class="ui small bordered image photo-content"
                                for="{{ form.photo.id }}"
                                title="{{ _("Click to upload a photo") }}"
                                style="display: none;">

                                <a class="ui right corner label photo-delete-icon" title="{{ _("Delete the photo") }}">
                                    <i class="times icon"></i>
                                </a>
                                <img src="" alt="User photo">
                            </label>
                            <label
                                class="ui centered photo-placeholder"
                                for="{{ form.photo.id }}"
                                title="{{ _("Click to upload a photo") }}">
                                <i class="massive centered portrait icon"></i>
                            </label>
                        {% endblock %}
                    </div>

                    <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) }}{% endblock %}
                    {% endif %}

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

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

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

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

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

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

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

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

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

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

            <div class="equal width fields">

                {% if "department" in form %}
                    {% block department_field scoped %}{{ profile.render_field(form.department) }}{% endblock %}
                {% endif %}

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

            <div class="equal width fields">

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

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

            </div>

            {% if "profile_url" in form %}
                {% block profile_uri_field scoped %}{{ profile.render_field(form.profile_url) }}{% endblock %}
            {% endif %}

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

            <h4 class="ui dividing header">{% trans %}Account settings{% endtrans %}</h4>

            {% if "user_name" in form %}
                {% block user_name_field scoped %}{{ profile.render_field(form.user_name) }}{% endblock %}
            {% endif %}

            {% if "groups" in form %}
                {% block groups_field scoped %}{{ profile.render_field(form.groups) }}{% endblock %}
            {% endif %}

            {% if "password1" in form %}
                {% block password_field scoped %}
                    <div class="two fields">
                        {{ profile.render_field(form.password1, noindicator=true) }}
                        {{ profile.render_field(form.password2, noindicator=true) }}
                    </div>
                {% endblock %}
            {% endif %}

            {% if user and user.can_manage_users %}

                <div class="ui message info">
                    <div class="header">
                        {% trans %}User password is not mandatory{% endtrans %}
                    </div>
                    <p>
                        {% if features.has_smtp %}
                            {% trans %}The user will not be able to authenticate unless the password is set, but they will be able to ask for a password initialization mail.{% endtrans %}
                        {% else %}
                            {% trans %}The user will not be able to authenticate unless the password is set.{% endtrans %}
                        {% endif %}
                    </p>
                </div>

            {% endif %}

            <div class="ui right aligned container">
                <div class="ui stackable buttons">
                    {% if not user %}
                        <a type="button" class="ui right floated button" href="{{ url_for('core.auth.login') }}">{{ _("Login page") }}</a>
                    {% endif %}
                    <button type="submit" class="ui right floated primary button" name="action" value="create-profile" id="create-profile">
                        {{ _("Submit") }}
                    </button>
                </div>
            </div>

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