{% extends "panel.html" %}

{% load i18n %}
{% load inventree_extras %}

{% block label %}user-display{% endblock %}

{% block heading %}
{% trans "Display Settings" %}
{% endblock %}

{% block content %}

<div class='row'>
    <table class='table table-striped table-condensed'>
        <tbody>
            {% include "InvenTree/settings/setting.html" with key="STICKY_HEADER" icon="fa-bars" user_setting=True %}
            {% include "InvenTree/settings/setting.html" with key="DATE_DISPLAY_FORMAT" icon="fa-calendar-alt" user_setting=True %}
            {% include "InvenTree/settings/setting.html" with key="FORMS_CLOSE_USING_ESCAPE" icon="fa-window-close" user_setting=True %}
            {% include "InvenTree/settings/setting.html" with key="PART_SHOW_QUANTITY_IN_FORMS" icon="fa-hashtag" user_setting=True %}
            {% include "InvenTree/settings/setting.html" with key="DISPLAY_SCHEDULE_TAB" icon="fa-calendar-alt" user_setting=True %}
        </tbody>
    </table>
</div>

<div class='panel-heading'>
    <h4>{% trans "Theme Settings" %}</h4>
</div>

<div class='row'>

    <div class='col-sm-6'>
        <form action='{% url "settings-appearance" %}' method='post'>
            {% csrf_token %}
            <input name='next' type='hidden' value='{% url "settings" %}'>
            <label for='theme' class=' requiredField'>
                <h6>{% trans "Select theme" %}</h6>
            </label>
            <div class='form-group input-group mb-3'>
                <select id='theme' name='theme' class='select form-control'>
                    {% get_available_themes as themes %}
                    {% get_user_color_theme request.user.username as user_theme %}
                    {% for theme in themes %}
                    <option value='{{ theme.key }}'{% if theme.key == user_theme %} selected{% endif%}>{{ theme.name }}</option>
                    {% endfor %}
                </select>
                <div class='input-group-append'>
                    <input type="submit" value="{% trans 'Set Theme' %}" class="btn btn-primary">
                </div>
            </div>
        </form>
    </div>
</div>

<div class='panel-heading'>
    <h4>{% trans "Language Settings" %}</h4>
</div>

<div class="row">
    <div class="col">
        <form action="{% url 'set_language' %}" method="post">
            {% csrf_token %}
            <input name="next" type="hidden" value="{% url 'settings' %}">
            <label for='language' class=' requiredField'>
                <h6>{% trans "Select language" %}</h6>
            </label>
            <div class='form-group input-group mb-3'>
                <select name="language" class="select form-control w-25">
                    {% get_current_language as LANGUAGE_CODE %}
                    {% get_available_languages as LANGUAGES %}
                    {% get_language_info_list for LANGUAGES as languages %}
                    {% if 'alllang' in request.GET %}{% define True as ALL_LANG %}{% endif %}
                    {% for language in languages %}
                        {% define language.code as lang_code %}
                        {% define locale_stats|keyvalue:lang_code as lang_translated %}
                        {% if lang_translated > 10 or lang_code == 'en' or lang_code == LANGUAGE_CODE %}{% define True as use_lang %}{% else %}{% define False as use_lang %}{% endif %}
                        {% if ALL_LANG or use_lang  %}
                        <option value="{{ lang_code }}"{% if lang_code == LANGUAGE_CODE %} selected{% endif %}>
                            {{ language.name_local }} ({{ lang_code }})
                            {% if lang_translated %}
                                {% blocktrans %}{{ lang_translated }}% translated{% endblocktrans %}
                            {% else %}
                                {% if lang_code == 'en' %}-{% else %}{% trans 'No translations available' %}{% endif %}
                            {% endif %}
                        </option>
                        {% endif %}
                    {% endfor %}
                </select>
                <div class='input-group-append'>
                    <input type="submit" value="{% trans 'Set Language' %}" class="btn btn btn-primary">
                </div>
            </div>
            <p>{% trans "Some languages are not complete" %}
            {% if ALL_LANG %}
            . <a href="{% url 'settings' %}">{% trans "Show only sufficent" %}</a>
            {% else %}
            {% trans "and hidden." %} <a href="?alllang">{% trans "Show them too" %}</a>
            {% endif %}
            </p>
    </form>
    </div>
    <div class="col-sm-6">
        <div class='alert alert-block alert-success'>
            <h5>{% trans "Help the translation efforts!" %}</h5>
            <p>{% trans "Native language translation of the web application is community contributed via crowdin. Contributions are welcomed and encouraged." %}</p>
            <p><a href="https://crowdin.com/project/inventree">{% trans "InvenTree Translation Project" %}</a></p>
        </div>
    </div>
</div>

{% endblock %}
