{% macro _category_path(category, truncated_path) %}
    {% set first_node, inner_nodes, last_node, truncated = truncated_path %}
    <span class="category-path">
        <ul {% if truncated %} title="{{ ' » '.join(category.chain_titles[:-1]) }}"{% endif %}>
            {% if first_node is not none %}<li>{{ first_node }}</li>{% endif %}
            {% if truncated %}
                <li data-tooltip-anchor>&hellip;</li>
            {% endif %}
            {% if inner_nodes is not none %}
                {% for inner_node in inner_nodes -%}
                <li>{{ inner_node }}</li>
            {%- endfor %}
            {% endif %}
            {% if last_node is not none %}<li>{{ last_node }}</li>{% endif %}
        </ul>
    </span>
{% endmacro %}

{% macro _category_item(category, truncated_path, extra_info='') %}
    <li class="category-box flexrow f-a-center">
        <div class="category-box-info">
            <a href="{{ category.url }}">{{ category.title }}</a>
            {{ _category_path(category, truncated_path) }}
            {{ extra_info }}
        </div>
        {{ caller() }}
    </li>
{% endmacro %}

{% macro user_category(category, truncated_path, is_manager) %}
    {% call _category_item(category, truncated_path) %}
        {% if is_manager %}
            <span title="{% trans %}You have management rights{% endtrans %}"
                  class="category-action right icon-medal active">
            </span>
        {% else %}
            <span title="{% trans %}You have favorited this category{% endtrans %}"
                  class="category-action right icon-star active">
            </span>
        {% endif %}
    {% endcall %}
{% endmacro %}

{% macro suggested_category(category, truncated_path) %}
    {% set category_action_extra %}
        <div class="category-action-extra">
            <a href="#"
               data-href="{{ url_for('.user_favorites_category_api', category_id=category.id) }}"
               title="{% trans %}Click here to add this category to your favorites.{% endtrans %}"
               class="icon-star active suggestion-favorite">
                <span>{% trans %}Add to favorites{% endtrans %}</span>
            </a>
        </div>
    {% endset %}
    {% call _category_item(category, truncated_path, category_action_extra) %}
        <a href="#"
           data-href="{{ url_for('.user_suggestions_remove', category_id=category.id) }}"
           title="{% trans %}Click here to remove this suggestion. It will not be suggested again.{% endtrans %}"
           class="category-action right active suggestion-remove">
            <i class="close icon"></i>
        </a>
    {% endcall %}
{% endmacro %}
