{% macro uniqueness(hash=False, errors=False, always=True) %}
<!-- Simple macro to load uniqueness in customization -->
<script src="{{ url_for('static', filename='uniqueness.js') }}"></script>
<script type="text/javascript">
    var unique = false
    $(document).ready( function () {
        unique = uniqueness({
            effect: 'fade',
            {% if always %}
            special_url: function () { // To change the initial link value for restore later
                var toSendLink = window.location.href.split('/')
                toSendLink[toSendLink.length - 1] = unique.turn                
                window.history.pushState(
                    '/' + unique.turn,
                    '/' + unique.turn,
                    '/' + window.location.href.split('/').slice(-2)[0] + '/' + (unique.turn + 1)
                )
            },
            {% endif %}
            {% if hash %} start_with: {{ hash - 1}} {% endif %}
        }, function (data) {
            if (unique.s_length > 2) $("[id^='ds']").removeClass('active')
            if (data === 'next' || data === 'back') $('#ds' + (unique.turn === -1 && data === 'back' ? unique.s_length  : unique.turn + 1)).addClass('active')
            else $('#ds' + (data + 1)).addClass('active')
        })
        {% if errors %} setTimeout(function () { if (unique.turn != (unique.s_length - 1)) unique.goto(unique.s_length - 1) }, 1000) {% endif %}
    })
</script>
{% endmacro %}

{% macro unique_btns(p, s, n, ar) %}
<!-- TODO: when multilang implemented text auto-detected form global flask var -->
<center>
<div class="btn-group">
  <button type="button" class="btn btn-warning" onclick="unique.back()">
      <span class='fa fa-arrow-left' style='padding-right: 1%'></span>
      {{ p }}
    </button>
  <button type="submit" class="btn btn-danger">{{ s }}</button>
  <button type="button" class="btn btn-primary" onclick="unique.next()">
      {{ n }}
      <span class='fa fa-arrow-right' style='padding-left: 2%'></span>
    </button>
</div> 
</center>
{% endmacro %}