{% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
{% import '@ChamiloTheme/Macros/box.html.twig' as display %}

{% block content %}
{% autoescape false %}
    {% if 'translate_html'|api_get_configuration_value %}
        <script>
            $(function () {
                // default
                $('.category-forum ').hide();

                {% if default_user_language %}
                $('.{{ default_user_language }}').show();
                {% endif %}

                $('#extra_language').attr('data-width', '200px');
                $('#extra_language option[value=""]').text('{{ 'Any' | get_lang | escape('js') }}');
                $('#extra_language').on('change', function() {
                    var selectedLanguageArray = $(this).val();
                    $('.category-forum ').hide();
                    $.each(selectedLanguageArray, function(index, selectedLanguage) {
                        if (selectedLanguage == '') {
                            $('.category-forum ').show();
                        } else {
                            $('.'+ selectedLanguage).show();
                        }
                    });
                });
            });
        </script>
    {% endif %}

    {{ form_content }}
    {{ search_filter }}

    {% set fold_forum_categories = 'forum_fold_categories'|api_get_configuration_value %}


    {% if data is not empty %}
        <div class="accordion forum" id="accordion-forum">
            {% for item in data %}

                {% set category_language_array = [] %}
                {% set category_language = '' %}
                {% for extra_field in item.extra_fields %}
                    {% if extra_field.variable == 'language' %}
                        {% set category_language_array = extra_field.value | split(';')  %}
                        {% set category_language = extra_field.value | replace({';': ' ' })  %}
                    {% endif %}
                {% endfor %}

                {{ display.card_collapse('accordion-forum', item)  }}

            {% endfor %}
        </div>
    {% else %}

        <div class="alert alert-info">
            {{ 'There is no forum in this category'|get_lang }}
        </div>

        {% if is_allowed_to_edit %}
            <div id="no-data-view" class="tool-view">
                <h2>{{ "Forum"|trans }}</h2>
                <img src="{{ "forum.png"|icon(64) }}" width="64" height="64">
                <div class="controls">
                    <a href="{{ _p.web_self }}?{{ _p.web_cid_query ~ "&action=addglossary" }}" class="btn btn-outline-primary">
                        {{ "Add forum category"|trans }}
                    </a>
                </div>
            </div>
        {% endif %}

    {% endif %}


{% endautoescape %}
{% endblock %}
