{% extends "WallabagCoreBundle::layout.html.twig" %}

{% block title %}{{ 'config.page_title'|trans }}{% endblock %}

{% block content %}

    <div class="row">
        <div class="col s12">
            <div class="card-panel settings">

                <div class="row">
                    <div class="div_tabs col s12">
                        <ul class="tabs">
                            <li class="tab col s3"><a class="active" href="#set1">{{ 'config.tab_menu.settings'|trans }}</a></li>
                            <li class="tab col s3"><a href="#set2">{{ 'config.tab_menu.rss'|trans }}</a></li>
                            <li class="tab col s3"><a href="#set3">{{ 'config.tab_menu.user_info'|trans }}</a></li>
                            <li class="tab col s3"><a href="#set4">{{ 'config.tab_menu.password'|trans }}</a></li>
                            <li class="tab col s3"><a href="#set5">{{ 'config.tab_menu.rules'|trans }}</a></li>
                            {% if is_granted('ROLE_SUPER_ADMIN') %}
                            <li class="tab col s3"><a href="#set6">{{ 'config.tab_menu.new_user'|trans }}</a></li>
                            {% endif %}
                        </ul>
                    </div>

                    <div id="set1" class="col s12">
                        {{ form_start(form.config) }}
                            {{ form_errors(form.config) }}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.config.theme) }}
                                    {{ form_errors(form.config.theme) }}
                                    {{ form_widget(form.config.theme) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.config.items_per_page) }}
                                    {{ form_errors(form.config.items_per_page) }}
                                    {{ form_widget(form.config.items_per_page) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.config.reading_speed) }}
                                    {{ form_errors(form.config.reading_speed) }}
                                    {{ form_widget(form.config.reading_speed) }}
                                    <p>
                                        {{ 'config.form_settings.reading_speed.help_message'|trans }}
                                        <a href="http://www.myreadspeed.com/calculate/">myreadspeed</a>
                                    </p>
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.config.language) }}
                                    {{ form_errors(form.config.language) }}
                                    {{ form_widget(form.config.language) }}
                                </div>
                            </div>

                            {{ form_widget(form.config.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
                            {{ form_rest(form.config) }}
                        </form>
                    </div>

                    <div id="set2" class="col s12">
                        {{ form_start(form.rss) }}
                            {{ form_errors(form.rss) }}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ 'config.form_rss.description'|trans }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    <label>{{ 'config.form_rss.token_label'|trans }}</label>
                                    <div>
                                        {% if rss.token %}
                                            {{ rss.token }}
                                        {% else %}
                                            <em>{{ 'config.form_rss.no_token'|trans }}</em>
                                        {% endif %}
                                        – <a href="{{ path('generate_token') }}">
                                        {% if rss.token %}
                                            {{ 'config.form_rss.token_reset'|trans }}
                                        {% else %}
                                            {{ 'config.form_rss.token_create'|trans }}
                                        {% endif %}</a>
                                    </div>
                                </div>
                            </div>
                            {% if rss.token %}
                            <div class="row">
                                <div class="input-field col s12">
                                    <label>{{ 'config.form_rss.rss_links'|trans }}</label>
                                    <ul>
                                        <li><a href="{{ path('unread_rss', {'username': rss.username, 'token': rss.token}) }}">{{ 'config.form_rss.rss_link.unread'|trans }}</a></li>
                                        <li><a href="{{ path('starred_rss', {'username': rss.username, 'token': rss.token}) }}">{{ 'config.form_rss.rss_link.starred'|trans }}</a></li>
                                        <li><a href="{{ path('archive_rss', {'username': rss.username, 'token': rss.token}) }}">{{ 'config.form_rss.rss_link.archive'|trans }}</a></li>
                                    </ul>
                                </div>
                            </div>
                            {% endif %}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.rss.rss_limit) }}
                                    {{ form_errors(form.rss.rss_limit) }}
                                    {{ form_widget(form.rss.rss_limit) }}
                                </div>
                            </div>

                            {{ form_widget(form.rss.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
                            {{ form_rest(form.rss) }}
                        </form>
                    </div>

                    <div id="set3" class="col s12">
                        {{ form_start(form.user) }}
                            {{ form_errors(form.user) }}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.user.name) }}
                                    {{ form_errors(form.user.name) }}
                                    {{ form_widget(form.user.name) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.user.email) }}
                                    {{ form_errors(form.user.email) }}
                                    {{ form_widget(form.user.email) }}
                                </div>
                            </div>

                            {% if twofactor_auth %}
                            <div class="row">
                                <div class="input-field col s12">
                                    {{ 'config.form_user.two_factor_description'|trans }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_widget(form.user.twoFactorAuthentication) }}
                                    {{ form_label(form.user.twoFactorAuthentication) }}
                                    {{ form_errors(form.user.twoFactorAuthentication) }}
                                </div>
                            </div>
                            {% endif %}

                            {{ form_widget(form.user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
                            {{ form_rest(form.user) }}
                        </form>
                    </div>

                    <div id="set4" class="col s12">
                        {{ form_start(form.pwd) }}
                            {{ form_errors(form.pwd) }}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.pwd.old_password) }}
                                    {{ form_errors(form.pwd.old_password) }}
                                    {{ form_widget(form.pwd.old_password) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.pwd.new_password.first) }}
                                    {{ form_errors(form.pwd.new_password.first) }}
                                    {{ form_widget(form.pwd.new_password.first) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.pwd.new_password.second) }}
                                    {{ form_errors(form.pwd.new_password.second) }}
                                    {{ form_widget(form.pwd.new_password.second) }}
                                </div>
                            </div>

                            {{ form_widget(form.pwd.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
                            {{ form_rest(form.pwd) }}
                        </form>
                    </div>

                    <div id="set5" class="col s12">
                        <div class="row">
                            <div class="input-field col s12">
                                <ul>
                                    {% for tagging_rule in app.user.config.taggingRules %}
                                    <li>
                                        {{ 'config.form_rules.if_label'|trans }}
                                        « {{ tagging_rule.rule }} »
                                        {{ 'config.form_rules.then_tag_as_label'|trans }}
                                        « {{ tagging_rule.tags|join(', ') }} »
                                        <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}">
                                            <i class="tool grey-text delete mdi-action-delete"></i>
                                        </a>
                                    </li>
                                    {% endfor %}
                                </ul>
                            </div>
                        </div>

                        {{ form_start(form.new_tagging_rule) }}
                            {{ form_errors(form.new_tagging_rule) }}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.new_tagging_rule.rule) }}
                                    {{ form_errors(form.new_tagging_rule.rule) }}
                                    {{ form_widget(form.new_tagging_rule.rule) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.new_tagging_rule.tags) }}
                                    {{ form_errors(form.new_tagging_rule.tags) }}
                                    {{ form_widget(form.new_tagging_rule.tags) }}
                                </div>
                            </div>

                            {{ form_widget(form.new_tagging_rule.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
                            {{ form_rest(form.new_tagging_rule) }}
                        </form>

                        <div class="row">
                            <div class="input-field col s12">
                                <h4>{{ 'config.form_rules.faq.title'|trans }}</h4>

                                <h5>{{ 'config.form_rules.faq.tagging_rules_definition_title'|trans }}</h5>
                                <p class="help">{{ 'config.form_rules.faq.tagging_rules_definition_description'|trans|raw }}</p>

                                <h5>{{ 'config.form_rules.faq.how_to_use_them_title'|trans }}</h5>
                                <p class="help">{{ 'config.form_rules.faq.how_to_use_them_description'|trans|raw }}</p>

                                <h5>{{ 'config.form_rules.faq.variables_available_title'|trans }}</h5>
                                <p class="help">
                                    {{ 'config.form_rules.faq.variables_available_description'|trans }}
                                </p>

                                <table class="bordered">
                                    <thead>
                                        <tr>
                                            <th>{{ 'config.form_rules.faq.variable_description.label'|trans }}</th>
                                            <th>{{ 'config.form_rules.faq.meaning'|trans }}</th>
                                            <th>{{ 'config.form_rules.faq.operator_description.label'|trans }}</th>
                                            <th>{{ 'config.form_rules.faq.meaning'|trans }}</th>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        <tr>
                                            <td>title</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.title'|trans }}</td>
                                            <td>&lt;=</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.less_than'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>url</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.url'|trans }}</td>
                                            <td>&lt;</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.strictly_less_than'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>isArchived</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.isArchived'|trans }}</td>
                                            <td>&gt;=</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.greater_than'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>isStarred</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.isStarred'|trans }}</td>
                                            <td>&gt;</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.strictly_greater_than'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>content</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.content'|trans }}</td>
                                            <td>=</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.equal_to'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>language</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.language'|trans }}</td>
                                            <td>!=</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.not_equal_to'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>mimetype</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.mimetype'|trans }}</td>
                                            <td>OR</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.or'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>readingTime</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.readingTime'|trans }}</td>
                                            <td>AND</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.and'|trans }}</td>
                                        </tr>
                                        <tr>
                                            <td>domainName</td>
                                            <td>{{ 'config.form_rules.faq.variable_description.domainName'|trans }}</td>
                                            <td>matches</td>
                                            <td>{{ 'config.form_rules.faq.operator_description.matches'|trans|raw }}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

                    {% if is_granted('ROLE_SUPER_ADMIN') %}
                    <div id="set6" class="col s12">
                        {{ form_start(form.new_user) }}
                            {{ form_errors(form.new_user) }}

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.new_user.username) }}
                                    {{ form_errors(form.new_user.username) }}
                                    {{ form_widget(form.new_user.username) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.new_user.plainPassword.first) }}
                                    {{ form_errors(form.new_user.plainPassword.first) }}
                                    {{ form_widget(form.new_user.plainPassword.first) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.new_user.plainPassword.second) }}
                                    {{ form_errors(form.new_user.plainPassword.second) }}
                                    {{ form_widget(form.new_user.plainPassword.second) }}
                                </div>
                            </div>

                            <div class="row">
                                <div class="input-field col s12">
                                    {{ form_label(form.new_user.email) }}
                                    {{ form_errors(form.new_user.email) }}
                                    {{ form_widget(form.new_user.email) }}
                                </div>
                            </div>

                            {{ form_widget(form.new_user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
                            {{ form_rest(form.new_user) }}
                        </form>
                    </div>
                    {% endif %}
                </div>

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