{% from 'events/management/_create_event_button.html' import create_event_button %}

<div class="category-container">
    <div class="category-header">
        <h1 class="category-title">
            {% block title %}
                {% if category.title == 'Home' and category.is_root %}
                    {% if category.children %}
                        {% trans %}Main categories{% endtrans %}
                    {% else %}
                        {% trans %}All events{% endtrans %}
                    {% endif %}
                {% else %}
                    {{ category.title }}
                {% endif %}
            {% endblock %}
        </h1>
        {% block cat_toolbar %}
            <div id="category-toolbar" class="toolbar">
                <div class="group">
                    <div id="search-box" class="search-box"
                         data-category="{{ {'id': category.id, 'isRoot': category.is_root, 'title': category.title} | tojson | forceescape }}"
                         {% if session.user and session.user.is_admin %}data-is-admin{% endif %}
                    ></div>
                </div>
                <div class="group">
                    {% block cat_create_event %}
                        {{ create_event_button(category, classes="highlight", text=_("Create event")) }}
                    {% endblock %}
                </div>
                <div class="group">
                    {% block cat_navigate %}
                        <button id="navigate-button" class="i-button icon-compass2"
                                title="{% trans %}Navigate categories{% endtrans %}">
                            {% trans %}Navigate{% endtrans %}
                        </button>
                    {% endblock %}
                </div>
                <div class="group">
                    {% block cat_parent %}
                        {% if not category.is_root %}
                            <a class="i-button icon-arrow-up" href="{{ category.parent.url }}">
                                {% trans %}Parent category{% endtrans %}
                            </a>
                        {% endif %}
                    {% endblock %}
                    {% block cat_export %}
                        <div id="category-calendar-link" data-category-id="{{ category.id }}"></div>
                    {% endblock %}
                    {% block cat_view_dropdown %}
                        <ind-with-tooltip>
                            <ind-menu>
                                <button class="i-button icon-eye arrow">
                                    <span data-tip-content="{% trans %}View{% endtrans %}">{% trans %}View{% endtrans %}</span>
                                </button>
                                <menu>
                                    {% if category.is_flat_view_enabled and category.children %}
                                        <li>
                                            <a href="{{ url_for('.display', category, flat=1) }}">{% trans %}All category events{% endtrans %}</a>
                                        </li>
                                    {% endif %}
                                    <li>
                                        <a href="{{ url_for('.previous_event', category) }}">{% trans %}Previous event{% endtrans %}</a>
                                    </li>
                                    <li>
                                        <a href="{{ url_for('.upcoming_event', category) }}">{% trans %}Upcoming event{% endtrans %}</a>
                                    </li>
                                    <li>
                                        <a href="{{ url_for('.closest_event', category) }}">{% trans %}Closest event{% endtrans %}</a>
                                    </li>
                                    <li>
                                        <a href="{{ url_for('.overview', category, period='day') }}">{% trans %}Today's events{% endtrans %}</a>
                                    </li>
                                    <li>
                                        <a href="{{ url_for('.overview', category, period='week') }}">{% trans %}Week's events{% endtrans %}</a>
                                    </li>
                                    <li>
                                        <a href="{{ url_for('.calendar', category) }}">{% trans %}Calendar{% endtrans %}</a>
                                    </li>
                                    <li>
                                        <a href="{{ url_for('.statistics', category) }}">{% trans %}Category statistics{% endtrans %}</a>
                                    </li>
                                </menu>
                            </ind-menu>
                        </ind-with-tooltip>
                    {% endblock %}
                    {% block cat_manage %}
                        {% if category.can_manage(session.user) %}
                            <a href="{{ url_for('categories.manage_content', category) }}"
                               class="i-button icon-edit"
                               title="{% trans %}Manage category{% endtrans %}"></a>
                        {% endif %}
                    {% endblock %}
                </div>
                {% block cat_user_favorites %}
                    {% if session.user and not category.is_root %}
                        <div class="group">
                            <div id="fav-button" data-category-id="{{ category.id }}"
                                 {{ 'data-favorited' if category in session.user.favorite_categories }}></div>
                        </div>
                    {% endif %}
                {% endblock %}
            </div>
        {% endblock %}
    </div>

    <div class="category-content-wrapper">
        <div class="category-content">
            {% include 'flashed_messages.html' %}
            {% block content %}{% endblock %}
        </div>
    </div>

    {% if self.sidebar() %}
        <div class="category-sidebar" id="sidebar" data-bypass-target="{% trans %}Skip to sidebar{% endtrans %}">
            {%- block sidebar %}{% endblock -%}
        </div>
    {% endif %}
</div>
<script>
    $('#navigate-button').on('click', function(evt) {
        $('<div>').categorynavigator({
            openInDialog: true,
            category: {{ category.id }},
            actionButtonText: $T.gettext('Navigate to'),
            dialogTitle: $T.gettext('Navigate to a category'),
            onAction: function(category) {
                window.location.href = build_url(Indico.Urls.Categories.display, {category_id: category.id});
            }
        });
    });
</script>
<script type="application/ld+json">
{{ json_ld|tojson }}
</script>
