{% import 'macros/form.html' as form %}
{% from 'tables/macros/filter_item.html' import filter_item %}

{% block table_control %}
    <div class="table-control d-flex gap-2">
        {% block table_filters %}
            <div id="filter-template" style="display:none;">
                {{ filter_item(table, '', '=', '') }}
            </div>

            {% snippet "tables/snippets/table_filters_modal.html", table=table %}

            <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
                <button class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#filters-modal">
                    <i class="fa fa-filter"></i> {{ _("Filters") }} <span class="badge bg-primary d-none" id="filters-counter">0</span>
                </button>
                <button class="btn btn-light" id="clear-all-filters" title="{{ _('Clear all filters') }}">
                    <i class="fa fa-times"></i>
                </button>
            </div>
        {% endblock %}

        {% block table_global_filters %}
            {% if table.bulk_actions %}
                <div class="dropdown d-inline-block">
                    <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <i class="fa fa-list-check"></i> {{ _("Row Actions") }}
                    </button>
                    <ul class="dropdown-menu" id="bulk-actions-menu">
                        {% for action in table.bulk_actions %}
                            <li>
                                <button class="dropdown-item" data-action="{{ action.action }}">
                                    {% if action.icon %}
                                        <i class="{{ action.icon }} me-1"></i>
                                    {% endif %}
                                    {{ action.label }}
                                </button>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            {% endif %}
        {% endblock %}

        {% block table_actions %}
            {% if table.table_actions %}
                <div class="dropdown d-inline-block">
                    <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <i class="fa fa-table"></i> {{ _("Table Actions") }}
                    </button>
                    <ul class="dropdown-menu" id="table-actions-menu">
                        {% for action in table.table_actions %}
                            <li>
                                <button class="dropdown-item" data-action="{{ action.action }}">
                                    {% if action.icon %}
                                        <i class="{{ action.icon }} me-1"></i>
                                    {% endif %}
                                    {{ action.label }}
                                </button>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            {% endif %}
        {% endblock %}
    </div>
{% endblock table_control %}

{% block table_container %}
    <div class="tabulator-wrapper">
        <div
            id="{{ table.id }}" class="tabulator-container"
            data-module="tables-tabulator"
            data-module-config="{{ h.tables_json_dumps(table.get_tabulator_config()) }}"
            data-module-row-actions="{{ h.tables_json_dumps(table.get_row_actions()) }}"
        >
            <span class="ap-loading-indicator">
                {% snippet "tables/snippets/table_skeleton.html" %}
            </span>
        </div>
    </div>
{% endblock %}
