
{% macro data_table_column_modal(name, columns) %}
<div class="modal fade" id="modal_{{ name }}" data-column-visibility="{{ name }}" tabindex="-1" role="dialog" aria-labelledby="data_table_modal_label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="{{ 'action.close'|trans }}"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="data_table_modal_label">{{ 'modal.columns.title'|trans }}</h4>
            </div>
            <div class="modal-body">
                <form name="{{ name }}_visibility">
                    {%- for title, headerOptions in columns -%}
                        {% if not headerOptions is iterable %}
                            {% set headerOptions = {'class': headerOptions} %}
                        {% endif %}
                        {% if headerOptions.title is defined %}
                            {% set headerTitle = headerOptions.title %}
                        {% else %}
                            {% set headerTitle = ('label.' ~ title)|trans %}
                        {% endif %}
                        {% if 'alwaysVisible' not in headerOptions.class %}
                            <div class="form-group">
                                <input type="checkbox" id="column_{{ title }}" name="{{ title }}"{% if is_visible_column(name, title, columns) %} checked="checked"{% endif %}>
                                <label class="control-label" for="column_{{ title }}">{{ headerTitle }}</label>
                            </div>
                        {% endif %}
                    {% endfor %}
                </form>
                <p>{{ 'modal.columns.description'|trans }}</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary pull-left" data-type="save">{{ 'action.save'|trans }}</button>
                <button type="button" class="btn btn-warning pull-left" data-type="reset">{{ 'action.delete'|trans }}</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'action.close'|trans }}</button>
            </div>
        </div>
    </div>
</div>
{% endmacro %}

{% macro datatable_header(tableName, columns, query, options) %}
    {% if query is not null %}
        {% set orderBy = options.orderBy|default(query.orderBy) %}
        {% set order = query.order|lower %}
    {% else %}
        {% set orderBy = false %}
        {% set order = false %}
    {% endif %}
    {% set striped = options.striped ?? false %}
    {% set bordered = options.bordered ?? false %}
    {% set reloadEvent = options.reload|default('') %}
    {% set translationDomain = options.translationDomain|default('messages') %}
    {% set translationPrefix = options.translationPrefix ?? 'label.' %}
    {% set boxClass = options.boxClass ?? 'box box-'  ~ admin_lte_context.widget.type ~ ' data_table' %}

    <div class="{{ boxClass }} datatable_{{ tableName }}">
        <div class="box-body no-padding">
            <div class="dataTables_wrapper form-inline dt-bootstrap">
                <table class="table {% if striped %}table-striped {% endif %}{% if bordered %}table-bordered {% endif %}table-hover dataTable" role="grid" data-reload-event="{{ reloadEvent }}">
                    <thead>
                        <tr>
                        {%- for title, headerOptions in columns -%}
                            {% if not headerOptions is iterable %}
                                {% set headerOptions = {'class': headerOptions} %}
                            {% endif %}
                            {% if not headerOptions.orderBy is defined %}
                                {% if orderBy is same as(false) %}
                                    {% set headerOptions = headerOptions|merge({'orderBy': false}) %}
                                {% else %}
                                    {% set headerOptions = headerOptions|merge({'orderBy': title}) %}
                                {% endif %}
                            {% endif %}
                            {% set headerClass = _self.data_table_column_class(tableName, columns, title) %}
                            {% if title != 'actions' and not headerOptions.orderBy is same as(false) %}
                                {% if orderBy == headerOptions.orderBy %}
                                    {% set headerClass = headerClass ~ ' sortable sorting_' ~ (order) %}
                                {% else %}
                                    {% set headerClass = headerClass ~ ' sortable sorting' %}
                                {% endif %}
                            {% endif %}
                            {% set headerTitle = '' %}
                            {% if headerOptions.title is defined %}
                                {% set headerTitle = headerOptions.title %}
                            {% elseif title is not empty and title != 'actions' %}
                                {% set headerTitle = (translationPrefix ~ title)|trans({}, translationDomain) %}
                            {% endif %}
                            <th data-field="{{ title }}" {% if not headerOptions.orderBy is same as(false) %}data-order="{{ headerOptions.orderBy }}" {% endif %}class="{{ headerClass }}">
                                {% if headerOptions.html_before is defined %}
                                    {{ headerOptions.html_before|raw }}
                                {% endif %}
                                {{ headerTitle }}
                                {% if headerOptions.html_after is defined %}
                                    {{ headerOptions.html_after|raw }}
                                {% endif %}
                            </th>
                        {%- endfor -%}
                        </tr>
                    </thead>
                    <tbody>
{% endmacro %}

{% macro data_table_column_class(name, columns, column) %}
{% apply spaceless %}
    {% set class = '' %}
    {% set always = false %}

    {% if columns[column] is defined %}
        {% set classes = columns[column] %}
        {# change the next if, once data_table_header_options() will be deleted #}
        {% if classes is iterable %}
            {% set classes = classes.class %}
            {% if columns[column].columnClass is defined %}
                {% set classes = classes ~ ' ' ~ columns[column].columnClass %}
            {% endif %}
        {% endif %}
        {% if 'alwaysVisible' in classes %}
            {# as this column should always be visible, we remove every class that includes hidden #}
            {% for tmp in classes|split(' ') %}
                {% if 'hidden' not in tmp %}
                    {% set class = class ~ ' ' ~ tmp %}
                {% endif %}
            {% endfor %}
        {% else %}
            {% if not is_visible_column(name, column, columns) %}
                {% set classes = classes ~ ' hidden' %}
            {% elseif not is_datatable_configured(name) %}
                {# needs to be a foreach, as classes like "hidden-xs" would match in: if 'hidden' in classes #}
                {% for tmp in classes|split(' ') %}
                    {% if 'hidden' == tmp %}
                        {% set classes = classes|replace({(tmp): ''}) %}
                    {% endif %}
                {% endfor %}
            {% else %}
                {# needs to be a foreach, as classes like "hidden-xs" would match in: if 'hidden' in classes #}
                {% for tmp in classes|split(' ') %}
                    {% if 'hidden' in tmp %}
                        {% set classes = classes|replace({(tmp): ''}) %}
                    {% endif %}
                {% endfor %}
            {% endif %}
            {% set class = classes %}
        {% endif %}
    {% endif %}

    {% if not class is empty %}
        {{ class }}
    {% endif %}
{% endapply %}
{% endmacro %}

{% macro data_table_footer(entries, route, multi_update_form) %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% if multi_update_form is not null %}
<div id="multi_update_form" style="display: none">
    {{ form_start(multi_update_form, {'attr': {'data-question': 'update_multiple'|trans}}) }}
    <label class="col-sm-1 col-xs-2 control-label" for="multi_update_table_action">
        <span class="pull-left"><i class="fas fa-level-up-alt fa-2x fa-rotate-90"></i></span>
    </label>
    <div class="col-sm-11 col-xs-10">
        {{ form_widget(multi_update_form.action) }}
    </div>
    {{ form_end(multi_update_form) }}
</div>
{% endif %}
{% if route is not empty and entries is not null%}
<div class="navigation text-center no-print">
    {{ pagination(entries, { routeName: route, 'css_container_class': 'pagination' }) }}
</div>
{% endif %}
{% endmacro %}

{% macro datatable_meta_column(entry, field) %}
    {% import "macros/widgets.html.twig" as widgets %}
    {% set metaField = entry.metaField(field.name) %}
    {% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
        {% set metaField = metaField.merge(field) %}
        {{ widgets.form_type_value(metaField.type, metaField.value, entry) }}
    {% endif %}
{% endmacro %}

{% macro datatable_multiupdate_all() %}
    <input type="checkbox" id="multi_update_all" class="multiupdater">
{% endmacro %}

{% macro datatable_multiupdate_row(id) %}
    <input type="checkbox" name="id" value="{{ id }}" class="multi_update_single multiupdater">
{% endmacro %}

{% macro data_table_header(name, columns, skipStripped, reloadEvent) %}
    {% deprecated 'The macro "data_table_header()" is deprecated since 1.3 and will be removed with 2.0, use "datatable_header()" instead' %}
    {{ _self.data_table_header_options(name, columns, {'skipStripped': skipStripped, 'reloadEvent': reloadEvent}) }}
{% endmacro %}

{% macro data_table_header_options(name, columns, options) %}
    {% deprecated 'The macro "data_table_header_options()" is deprecated since 1.3 and will be removed with 2.0, use "datatable_header()" instead' %}
    {% set skipStripped = options.skipStripped|default(true) %}
    {% set reloadEvent = options.reloadEvent|default('') %}
    {% set translationDomain = options.translationDomain|default('messages') %}
    {# |default does not work here, as the prefix might be an empty string #}
    {% set translationPrefix = 'label.' %}
    {% if options.translationPrefix is defined %}
        {% set translationPrefix = options.translationPrefix %}
    {% endif %}

<div class="box box-{{ admin_lte_context.widget.type }} data_table" id="datatable_{{ name }}">
    <div class="box-body no-padding">
        <div class="dataTables_wrapper form-inline dt-bootstrap">
            <div class="row">
                <div class="col-sm-12">
                    <table class="table {% if not skipStripped %}table-striped {% endif %}table-hover dataTable" role="grid" data-reload-event="{{ reloadEvent }}">
                        <thead>
                        <tr>
                            {%- for title, class in columns -%}
                                <th data-field="{{ title }}" class="{{ _self.data_table_column_class(name, columns, title) }}">{% if title is not empty and title != 'actions' %}{{ (translationPrefix ~ title)|trans({}, translationDomain) }}{% endif %}</th>
                            {%- endfor -%}
                        </tr>
                        </thead>
                        <tbody>
{% endmacro %}
