{% import 'macros/tentacles.html' as m_tentacles %}

{% macro config_evaluator_card(startup_config, evaluator_name, info, config_type, strategy=False) %}
    <a href="#" onclick="return false;"
       class="col-md-6 col-lg-4 list-group-item list-group-item-action waves-effect {{ 'd-none' if strategy }} {{'list-group-item-success' if info['activation'] else 'list-group-item-light'}} config-element evaluator-config-element"
       id={{evaluator_name}} name={{ info['advanced_class']['name'] if info['advanced_class'] else evaluator_name }}
       config-type={{config_type}} config-key={{evaluator_name}} current-value={{info['activation']}} config-value={{info['activation']}} startup-config-value={{startup_config[evaluator_name]}}
       requirements="{{info['advanced_class']['requirements'] if info['advanced_class']['requirements'] else info['requirements']}}"
       default-elements="{{info['advanced_class']['default-config'] if info['advanced_class']['default-config'] else info['default-config']}}"
       requirements-min-count="{{info['advanced_class']['requirements-min-count'] if info['advanced_class']['requirements-min-count'] else info['requirements-min-count']}}">
        {% if not strategy %}
        <span class="float-left {{'d-none' if not info['required']}}" role="required-flag">
            <i class="fa fa-flag {{'red-text' if not info['activation']}}"
               data-toggle="tooltip" data-placement="top"
               title="Should be activated when using the current strategies">
            </i>
        </span>
        {% endif %}
        {{ evaluator_name }}
        {% if info['advanced_class'] %}
        <span><i class="fa fa-graduation-cap" data-toggle="tooltip" data-placement="top" title="Advanced tentacle"></i></span>
        {% endif %}
        <span class="float-right">
            <span class="badge {{'badge-warning' if startup_config[evaluator_name] != info['activation'] else ('badge-success' if info['activation'] else 'badge-secondary')}}">
                {{('Activation pending restart' if info['activation'] else 'Deactivation pending restart') if startup_config[evaluator_name] != info['activation'] else ('Activated' if info['activation'] else 'Deactivated')}}
            </span>
            <button class="btn btn-outline-primary btn-md waves-effect"  data-toggle="modal" data-target="#{{evaluator_name}}Modal" no-activation-click="true"><i class="fa fa-info-circle" no-activation-click="true"></i></button>
        </span>
    </a>
    {{ evaluator_card_modal(evaluator_name, info, strategy) }}
{% endmacro %}

{% macro tentacle_evaluator_card(startup_config, evaluator_name, info, config_type, strategy=False) %}
    <a href="#" onclick="return false;"
       class="col-md-6 col-lg-4 list-group-item list-group-item-action waves-effect {{'list-group-item-success' if info['activation'] else 'list-group-item-light'}} config-element evaluator-config-element"
       id={{evaluator_name}} name={{ info['advanced_class']['name'] if info['advanced_class'] else evaluator_name }}
       config-type={{config_type}} config-key={{evaluator_name}} current-value={{info['activation']}} config-value={{info['activation']}} startup-config-value={{startup_config[evaluator_name]}}
       requirements="{{info['advanced_class']['requirements'] if info['advanced_class'] and info['advanced_class']['requirements'] else info['requirements']}}"
       default-elements="{{info['advanced_class']['default-config'] if info['advanced_class'] and info['advanced_class']['default-config'] else info['default-config']}}"
       requirements-min-count="{{info['advanced_class']['requirements-min-count'] if info['advanced_class'] and info['advanced_class']['requirements-min-count'] else info['requirements-min-count']}}">
        {{ evaluator_name }}
        {% if info['advanced_class'] %}
        <span><i class="fa fa-graduation-cap" data-toggle="tooltip" data-placement="top" title="Advanced tentacle"></i></span>
        {% endif %}
        <span class="float-right">
            <span class="badge {{'badge-warning' if startup_config[evaluator_name] != info['activation'] else ('badge-success' if info['activation'] else 'badge-secondary')}}">
                {{('Activation pending restart' if info['activation'] else 'Deactivation pending restart') if startup_config[evaluator_name] != info['activation'] else ('Activated' if info['activation'] else 'Deactivated')}}
            </span>
            <button class="btn btn-outline-primary btn-md waves-effect"  data-toggle="modal" data-target="#{{evaluator_name}}Modal" no-activation-click="true"><i class="fa fa-info-circle" no-activation-click="true"></i></button>
        </span>
    </a>
    {{ evaluator_card_modal(evaluator_name, info, strategy) }}
{% endmacro %}

{% macro evaluator_card_modal(evaluator_name, info, strategy=False) %}
    <div class="modal fade" id="{{evaluator_name}}Modal" tabindex="-1" role="dialog" aria-labelledby="#{{evaluator_name}}ModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content modal-text">
          <div class="modal-header primary-text">
              <h5 class="modal-title" id="#{{evaluator_name}}ModalLabel">
                  <a href="{{ url_for('config_tentacle', name=(info['advanced_class']['name'] if info['advanced_class'] else evaluator_name)) }}">{{info['advanced_class']['name'] if info['advanced_class'] else evaluator_name}}</a>
              </h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
              {{ m_tentacles.tentacle_description(info, strategy, info['advanced_class']['name'] if info['advanced_class'] else evaluator_name ) }}
          </div>
          <div class="modal-footer">
            <a href="{{ url_for('config_tentacle', name=(info['advanced_class']['name'] if info['advanced_class'] else evaluator_name)) }}"
               class="btn btn-outline-primary waves-effect" role="button">Configure</a>
            <button class="btn btn-primary waves-effect" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
{% endmacro %}
