{# This template is shared by the desktop, mobile and kiosk versions of NEMO. #}
{# It is included from templates/calendar/configuration.html for the desktop version #}
{# from templates/mobile/new_reservation.html for the mobile version. #}
{# and from templates/kiosk/tool_reservation.html for the kiosk version. #}
{# If you modify this template then please check that all 3 versions work. #}
{% load custom_tags_and_filters %}
<div class="form-group">
    {% if config_error %}<div class="alert alert-danger">{{ config_error }}</div>{% endif %}
    {% for config in configurations %}
        {% if config.prompt %}<p>{{ config.prompt }}</p>{% endif %}
        {% if config|class_name != "ConfigurationPrecursor" %}
            {# Regular config #}
            {% if config.current_settings_as_list|length == 1 %}
                <label for="configuration_{{ config.id }}__slot_0__display_order_{{ config.display_order }}">{{ config.name }}:</label>
                <select class="form-control"
                        id="configuration_{{ config.id }}__slot_0__display_order_{{ config.display_order }}"
                        name="configuration_{{ config.id }}__slot_0__display_order_{{ config.display_order }}">
                    {% if config.absence_string %}<option value="">{{ config.absence_string }}</option>{% endif %}
                    {% for setting in config.available_settings_as_list %}
                        <option value={{ forloop.counter0 }}>{{ setting }}
                        </option>
                    {% endfor %}
                </select>
            {% else %}
                {% if config.configurable_item_name %}
                    {{ config.name }}:
                    <br>
                {% endif %}
                {% for slot in config.range_of_configurable_items %}
                    <label for="configuration_{{ config.id }}__slot_{{ slot }}__display_order_{{ config.display_order }}">
                        {% if config.configurable_item_name %}
                            {{ config.configurable_item_name }}
                        {% else %}
                            {{ config.name }}
                        {% endif %}
                        #{{ slot|add:1 }}:
                    </label>
                    <select class="form-control"
                            id="configuration_{{ config.id }}__slot_{{ slot }}__display_order_{{ config.display_order }}"
                            name="configuration_{{ config.id }}__slot_{{ slot }}__display_order_{{ config.display_order }}">
                        {% if config.absence_string %}<option value="">{{ config.absence_string }}</option>{% endif %}
                        {% for setting in config.available_settings_as_list %}
                            <option value={{ forloop.counter0 }}>{{ setting }}
                            </option>
                        {% endfor %}
                    </select>
                    <br>
                {% endfor %}
            {% endif %}
        {% else %}
            {# Precursor #}
            {% with precursor_config=config %}
                {% if precursor_config.configurable_item_name %}
                    {{ precursor_config.name }}:
                    <br>
                {% endif %}
                {% for slot in precursor_config.configurationprecursorslot_set.all %}
                    <div class="row form-group" style="margin-bottom: 0">
                        <div class="col-sm-6">
                            <label for="configurationslot_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}">
                                {% if precursor_config.configurable_item_name %}
                                    {{ precursor_config.configurable_item_name }}
                                {% else %}
                                    {{ precursor_config.name }}
                                {% endif %}
                                :
                            </label>
                            {% if slot.permanent_setting %}
                                <input type="hidden"
                                       value="irrelevant"
                                       name="configurationslot_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}">
                            {% endif %}
                            <select class="form-control"
                                    id="configurationslot_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}"
                                    name="configurationslot_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}"
                                    {% if slot.permanent_setting %}disabled{% endif %}>
                                {% if slot.permanent_setting %}
                                    <option selected value="">{{ slot.setting }}</option>
                                {% else %}
                                    {% with available_settings=slot|precursor_slot_available_settings:reservation_start %}
                                        {% if precursor_config.absence_string %}<option value="">{{ precursor_config.absence_string }}</option>{% endif %}
                                        {% for setting in precursor_config.available_settings_as_list %}
                                            {% if setting in available_settings %}
                                                <option value={{ forloop.counter0 }}>{{ setting }}
                                                </option>
                                            {% endif %}
                                        {% endfor %}
                                    {% endwith %}
                                {% endif %}
                            </select>
                        </div>
                        <div class="col-sm-6">
                            <label for="position_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}">
                                Position:
                            </label>
                            {% if slot.permanent_position %}
                                <input type="hidden"
                                       value="irrelevant"
                                       name="position_{{ slot.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}">
                            {% endif %}
                            <select class="form-control"
                                    id="position_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}"
                                    name="position_{{ precursor_config.id }}__slot_{{ slot.id }}__display_order_{{ precursor_config.display_order }}"
                                    {% if slot.permanent_position %}disabled{% endif %}>
                                {% if slot.permanent_position %}
                                    <option selected value="">{{ slot.position }}</option>
                                {% else %}
                                    {% with av_slots=slot|precursor_slot_available_positions:reservation_start %}
                                        {% if av_slots|length != 1 %}<option value="">Any</option>{% endif %}
                                        {% for av_slot in av_slots %}<option class="disabled" value="{{ av_slot }}">{{ av_slot }}</option>{% endfor %}
                                    {% endwith %}
                                {% endif %}
                            </select>
                        </div>
                    </div>
                    <br>
                {% endfor %}
            {% endwith %}
        {% endif %}
        <p>
        {% endfor %}
    </div>
    {% if able_to_self_configure %}
        <div class="form-group">
            <div class="checkbox">
                <label data-toggle="tooltip"
                       data-placement="bottom"
                       title="Checking this box indicates you wish to perform the tool configuration instead of having the {{ facility_name }} staff configure the tool. If you configure the tool, you are responsible for recording the configuration change.">
                    <input type="checkbox" name="self_configuration">
                    I will configure the tool myself
                </label>
            </div>
        </div>
    {% endif %}
    <div class="form-group">
        <label for="additional_information">Do you have anything else to add? (Optional)</label>
        <textarea name="additional_information"
                  id="additional_information"
                  rows="7"
                  class="form-control"
                  maxlength="{{ additional_information_maximum_length }}"
                  placeholder="Please provide any additional information regarding tool configuration for your reservation (using less than 3000 characters)."></textarea>
    </div>
