{% import 'macros/text.html' as m_text %}

{% macro tentacle_description(info, strategy, name) %}
    {% if info['advanced_class'] %}
          <h4>Advanced tentacle: {{info['advanced_class']['name']}}</h4>
          <p>
            {{m_text.text_split_lines(info['advanced_class']['description'])}}
          </p>
          <h5>{{info['advanced_class']['name']}} is based on {{ tentacle_with_link_list(info['advanced_class']['base_classes']) }}</h5>
          {% if info['advanced_class']['default-config'] %}
                <p>
                    {{ default_config_with_apply(info['advanced_class']['default-config'], strategy, info['advanced_class']['name'], info['advanced_class']['requirements']) }}
                </p>
          {% endif %}
      {% else %}
          {{m_text.text_split_lines(info['description'])}}
          {% if info['default-config'] %}
                <p>
                    {{ default_config_with_apply(info['default-config'], strategy, name, info['requirements']) }}
                </p>
          {% endif %}
      {% endif %}
{% endmacro %}

{% macro tentacle_horizontal_description(info, strategy) %}
    <div class="row">
    {% if info['advanced_class'] %}
        <div class="col-8">
            <h4>Advanced tentacle: {{info['advanced_class']['name']}}</h4>
            <p>
                {{m_text.text_split_lines(info['advanced_class']['description'])}}
            </p>
            <h5>{{info['advanced_class']['name']}} is based on {{ tentacle_with_link_list(info['advanced_class']['base_classes']) }}</h5>
        </div>
        {% if info['advanced_class']['requirements'] %}
            <div class="col border-left border-dark">
                {{ requirements_and_default_config(info['advanced_class']['requirements'], info['advanced_class']['default-config'], strategy, info['advanced_class']['name'] ) }}
            </div>
        {% endif %}
    {% else %}
        <div class="col-8">
            {{m_text.text_split_lines(info['description'])}}
        </div>
        {% if info['requirements'] %}
            <div class="col border-left border-dark">
                {{ requirements_and_default_config(info['requirements'], info['default-config'], strategy, info['name']) }}
            </div>
        {% endif %}
    {% endif %}
    </div>
{% endmacro %}

{% macro tentacle_with_link(tentacle_name) %}
    <a href="{{ url_for('config_tentacle', name=(tentacle_name)) }}">{{ tentacle_name }}</a>
{% endmacro %}

{% macro tentacle_with_link_list(tentacle_list) %}
    {% if tentacle_list == ["*"] %}
        All tentacles returning values between -1 and 1.
    {% else %}
        {% for tentacle in tentacle_list %}
            {{ tentacle_with_link(tentacle) }}
        {% endfor %}
    {% endif %}
{% endmacro %}

{% macro default_config_with_apply(default_config, strategy, name, requirements) %}
    <div>
        <h5>Default configuration:
            {% if strategy or (not strategy and requirements|length > 1) %}
             <button type="button"
                   config-type="evaluator_list_config"
                   id="applyDefaultConfig"
                   tentacle="{{ name }}"
                   class="btn btn-sm btn-outline-green waves-effect config-element float-right">
               <i class="fas fa-check"></i> Activate
            </button>
            {% endif %}
        </h5>
    </div>
    {{ tentacle_with_link_list(default_config) }}
{% endmacro %}

{% macro requirements_and_default_config(requirements, default_config, strategy, name) %}
    <h5>Compatible {{ 'evaluators' if strategy else 'strategies' }}:</h5>
        {{ tentacle_with_link_list(requirements) }}
    <hr>
    {{ default_config_with_apply(default_config, strategy, name, requirements) }}
{% endmacro %}
