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

{% block table_control %}
    <div class="table-control d-flex flex-wrap">
        {% 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-light align-items-baseline" data-bs-toggle="modal" data-bs-target="#filters-modal" title="{{ _('Manage Filters') }}">
                    <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_columns %}
            {% snippet "tables/snippets/table_columns_modal.html", table=table %}

            <button class="btn btn-light align-items-baseline" data-bs-toggle="modal" data-bs-target="#columns-modal" title="{{ _('Manage Columns') }}">
                <i class="fa fa-columns"></i>
                {{ _("Columns") }}
                <span class="badge bg-primary d-none" id="hidden-columns-badge">
                    <i class="fa fa-eye-slash text-white"></i>
                    <span id="hidden-columns-counter">0</span>
                </span>
            </button>
        {% endblock %}

        {% block table_global_filters %}
            {% if table.bulk_actions %}
                <div class="dropdown d-inline-block">
                    <button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"
                    title="{{ _('Row actions') }}">
                        <i class="fa fa-table-list"></i> {{ _("Row Actions") }}
                    </button>
                    <ul class="dropdown-menu" id="bulk-actions-menu">
                        {% for action in table.bulk_actions %}
                            <li>
                                {% do action.attrs.update({'class': ('dropdown-item ' ~ action.attrs.get('class', '')).strip()}) %}
                                <button data-action="{{ action.action }}" {{ attributes(action.attrs) }}>
                                    {% 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-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"
                    title="{{ _('Table actions') }}">
                        <i class="fa fa-table"></i> {{ _("Table Actions") }}
                    </button>
                    <ul class="dropdown-menu" id="table-actions-menu">
                        {% for action in table.table_actions %}
                            <li>
                                {% do action.attrs.update({'class': ('dropdown-item ' ~ action.attrs.get('class', '')).strip()}) %}
                                <button data-action="{{ action.action }}" {{ attributes(action.attrs) }}>
                                    {% if action.icon %}
                                        <i class="{{ action.icon }} me-1"></i>
                                    {% endif %}
                                    {{ action.label }}
                                </button>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            {% endif %}
        {% endblock %}

        {% block table_exporters %}
            {% if table.exporters %}
                <div class="dropdown d-inline-block">
                    <button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"
                    title="{{ _('Export Table Data') }}">
                        <i class="fa fa-download"></i> {{ _("Export") }}
                    </button>
                    <ul class="dropdown-menu" id="table-exporters-menu">
                        {% for exporter in table.exporters %}
                            <li>
                                <button class="dropdown-item" data-exporter="{{ exporter.name }}">
                                    {% if exporter.icon %}
                                        <i class="{{ exporter.icon }} me-1"></i>
                                    {% endif %}
                                    {{ exporter.label }}
                                </button>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            {% endif %}
        {% endblock %}

        {% block table_refresh %}
            <button class="btn" id="refresh-table" title="{{ _('Refresh Table') }}">
                <i class="fa fa-arrows-rotate"></i>
            </button>
        {% endblock %}

        {% block table_total_count %}
            <div class="d-flex align-items-center ms-auto">
                <span id="total-count-value" class="me-1">
                    0
                </span>
                <span>{{ _('row(s)') }}</span>
            </div>

            <a class='btn d-none d-sm-inline-block' id='btn-fullscreen' title='Fullscreen toggle'><i class='fa fa-expand'></i></a>
        {% 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()) }}"
        >
            {% snippet "tables/snippets/table_skeleton.html" %}
        </div>
    </div>
{% endblock %}
