{#
 # ---------------------------------------------------------------------
 # Formcreator is a plugin which allows creation of custom forms of
 # easy access.
 # ---------------------------------------------------------------------
 # LICENSE
 #
 # This file is part of Formcreator.
 #
 # Formcreator is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.
 #
 # Formcreator 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 General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
 # ---------------------------------------------------------------------
 # @copyright Copyright © 2011 - 2021 Teclib'
 # @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
 # @link      https://github.com/pluginsGLPI/formcreator/
 # @link      https://pluginsglpi.github.io/formcreator/
 # @link      http://plugins.glpi-project.org/#/plugin/formcreator
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}
<div class="col-12 col-xxl-12 flex-column" data-itemtype="PluginFormcreatorCondition">
    <div class="d-flex flex-row flex-wrap flex-xl-nowrap">
        <div class="row flex-row align-items-start flex-grow-1">
            <div class="row flex-row">

                {# Logic operator #}
                {% set elements = call('PluginFormcreatorCondition::getEnumShowLogic') %}
                {% set options = {
                    'value': condition.fields['show_logic']|verbatim_value,
                    'width': '100%',
                    'display_emptychoice': false,
                    'field_class': 'col-12 col-sm-1',
                    'no_label': true
                } %}
                {% set field %}
                    {% do call('Dropdown::showFromArray', ['_conditions[show_logic][]', elements, options]) %}
                {% endset %}
                {{ fields.field(name, field, label, options|merge({'id': 'dropdown_' ~ name ~ '_' ~ options.rand})) }}

                {# condition field #}
                {% set options = {
                    'field_class': 'col-12 col-sm-5',
                    'no_label': true,
                    'rand': random(),
                    'width': '100%',
                } %}
                {% set excludeQuestions = call('PluginFormcreatorCondition::getQuestionsExclusion', [parent]) %}
                {% set form = call('PluginFormcreatorForm::getByItem', [parent]) %}
                {% set field %}
                    {% do call('PluginFormcreatorQuestion::dropdownForForm', [form, excludeQuestions, '_conditions[plugin_formcreator_questions_id][]', condition.fields['plugin_formcreator_questions_id'], options]) %}
                {% endset %}
                {{ fields.field(name, field, label, options|merge({'id': 'dropdown_' ~ name ~ '_' ~ options.rand})) }}

                {# operator field #}
                {% set elements = call('PluginFormcreatorCondition::getEnumShowCondition') %}
                {% set options = {
                    'value': condition.fields['show_condition']|verbatim_value,
                    'width': '100%',
                    'display_emptychoice': false,
                    'field_class': 'col-12 col-sm-1',
                    'no_label': true
                } %}
                {% set field %}
                    {% do call('Dropdown::showFromArray', ['_conditions[show_condition][]', elements, options]) %}
                {% endset %}
                {{ fields.field(name, field, label, options|merge({'id': 'dropdown_' ~ name ~ '_' ~ options.rand})) }}

                {# value field #}
                {% set options = {
                    'width': '100%',
                    'display_emptychoice': false,
                    'field_class': 'col-12 col-sm-3',
                    'no_label': true
                } %}
                {{ fields.textField('_conditions[show_value][]', condition.fields['show_value']|verbatim_value, '', options) }}

                <div class="col-12 col-sm-1 mb-3">
                    <button class="btn btn-primary me-2" type="button" name="add" onclick="plugin_formcreator_addEmptyCondition(this, '', '')">
                        <i class="fas fa-plus-circle" style="cursor: pointer;"></i>
                    </button>
                </div>
                <div class="col-12 col-sm-1 mb-3">
                    <button class="btn btn-primary me-2" type="button" name="add" onclick="plugin_formcreator_removeNextCondition(this, '', '')">
                        <i class="fas fa-minus-circle" style="cursor: pointer;"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>