{% extends 'layout/management_page.html' %}

{% macro delete_category_button(category, classes="i-button") %}
    {% set confirmation_message -%}
        {% trans category=category.title %}
            Do you really want to delete the category &quot;{{ category }}&quot;?
        {% endtrans %}
    {%- endset %}
    {% if category.is_empty %}
        {% set tooltip -%}
            {% trans %}Delete category{% endtrans %}
        {%- endset %}
    {% else %}
        {% set classes = classes + " disabled" %}
        {% set tooltip -%}
            {% trans %}This category cannot be deleted because it is not empty.{% endtrans %}
        {%- endset %}
    {% endif %}
    <a class="{{ classes }} icon-remove js-delete-category"
       title="{{ tooltip|forceescape }}"
       data-confirm="{{ confirmation_message }}"
       data-title="{% trans %}Delete category{% endtrans %}"
       data-href="{{ url_for('categories.delete', category) }}"
       data-method="POST"></a>
{% endmacro %}

{% macro move_category_button(category, classes="i-button") %}
    <a class="{{ classes }} icon-transmission js-move-category"
       title="{% trans %}Move to another category{% endtrans %}"
       data-href="{{ url_for('categories.move', category) }}"
       data-category-id="{{ category.id }}"></a>
{% endmacro %}

{% block banner_title %}
    {{ category.title }}
{% endblock %}

{% block banner_actions %}
    <div class="toolbar">
        <div class="group">
            {% if not category.is_root %}
                {{ move_category_button(category, classes="i-button borderless") }}
                {{ delete_category_button(category, classes="i-button borderless") }}
            {% endif %}
            {{ template_hook('category-management-after-banner-actions', category=category) }}
        </div>
    </div>
    {% if not category.is_root %}
        <script>
            setupCategoryMoveButton({{ category.parent.id }});
        </script>
    {% endif %}
{% endblock %}

{% block side_menu %}
    {{ render_sidemenu('category-management-sidemenu', category=category, active_item=active_menu_item) }}
{% endblock %}

{% block display_view_button %}
    <div class="group">
        <a href="{{ category.url }}"
           class="icon-switchon highlight i-button"
           title="{% trans %}See the display page of the category{% endtrans %}">
            <span>{%- trans %}Switch to display view{% endtrans -%}</span>
        </a>
    </div>
{% endblock %}
