{#
 * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
 <info@champs-libres.coop> / <http://www.champs-libres.coop>
 *
 * This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
#}

{% extends "@ChillMain/layout.html.twig" %}

{% block title %}{{ export.title|trans }}{% endblock %}

{% block css %}
    {{ encore_entry_link_tags('mod_pickentity_type') }}
    {{ encore_entry_link_tags('mod_pick_rolling_date') }}
{% endblock %}

{% block js %}
    {{ encore_entry_script_tags('mod_pickentity_type') }}
    {{ encore_entry_script_tags('page_export') }}
    {{ encore_entry_script_tags('vue_export_action_goal_result') }}
    {{ encore_entry_script_tags('mod_pick_rolling_date') }}
{% endblock js %}

{% block content  %}
    <div class="col-md-10">

        {{ include('@ChillMain/Export/_breadcrumb.html.twig') }}

        <h1>{{ export.title|trans }}</h1>

        <p>{{ export.description|trans }}</p>

        {{ form_start(form) }}

        {% if form.children.export.children.filters is defined %}
            {% if form.children.export.children.filters is not empty%}

            <section class="filter mb-4">
                <h2>{{ 'Filters'| trans }}</h2>

                {{ form_errors(form.children.export.children.filters) }}

                <div class="flex-table">
                {% for filter_form in form.children.export.children.filters %}
                    <div class="item-bloc no-altern">

                        {{ form_widget(filter_form.enabled, {
                            'label': filter_form.vars.label,
                            'label_attr': { 'class': 'h6' },
                            'attr': { 'data-display-target': filter_form.vars.id }
                        }) }}

                        <div data-display-show-hide="{{ filter_form.vars.id }}">
                            {{ form_widget(filter_form.form) }}
                            {{ form_errors(filter_form) }}
                        </div>

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

            {% else %}
                {# render the children, to mark the widget as 'rendered' #}
                {{ form_widget(form.children.export.children.filters) }}
            {% endif %}
        {% endif %}

        {% if form.children.export.children.aggregators is defined %}
            {% if form.children.export.children.aggregators is not empty %}

            <section class="aggregator mb-4">
                <h2>{{ 'Aggregators'| trans }}</h2>

                <div class="flex-table">
                {% for aggregator_form in form.children.export.children.aggregators %}
                    <div class="item-bloc no-altern">

                        {{ form_widget(aggregator_form.enabled, {
                            'label': aggregator_form.vars.label,
                            'label_attr': { 'class': 'h6' },
                            'attr': { 'data-display-target': aggregator_form.vars.id }
                        }) }}

                        <div data-display-show-hide="{{ aggregator_form.vars.id }}">
                            {{ form_widget(aggregator_form.form) }}
                            {{ form_errors(aggregator_form) }}
                        </div>

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

            {% else %}
                {# render the children, to mark the widget as 'rendered' #}
                {{ form_widget(form.children.export.children.aggregators) }}
            {% endif %}
        {% endif %}


        {% if form.children.export.children.export.children|length > 0 %}

            <style>
                div#export_export_fields { column-count: 2; }
            </style>
            <section class="parameter mb-4">
                <h2>
                    {{ 'Export parameters'|trans }}
                </h2>
                {{ form_widget(form.children.export.children.export) }}
            </section>

        {% else %}
            {# render the children, to mark the widget as 'rendered' #}
            {{ form_widget(form.children.export.children.export) }}
        {% endif %}

        {% if form.children.export.children.pick_formatter is defined %}
            <section class="formatter mb-4">
                <h2>
                    {{ 'Formatter'| trans }}
                </h2>
                <p>
                    {{ 'Choose the formatter'|trans }}
                </p>
                {{ form_row(form.children.export.children.pick_formatter.children.alias, { 'label' : 'Formatter' }) }}
            </section>
        {% endif %}

        <p>{{ form_widget(form.submit, { 'attr' : { 'class' : 'btn btn-create' }, 'label' : 'Go to formatter options' } ) }}</p>
        {{ form_end(form) }}

    </div>
{% endblock content  %}
