{# def data, columns=[], order=[], empty_message=None, info_message=None, searching=True, buttons=[], paging=True, page_length=25, length_change=True, buttons_cfg={}, layout={}, server_side=False, state_save=True, auto_width=False, responsive=False, rowgroup=False, fixed_header=False, scroll_y=False #}
{#css vendor/bootstrap5/css/bootstrap.min.css, vendor/datatables/css/dataTables.dataTables.css, vendor/datatables-extensions/Buttons/css/buttons.dataTables.min.css, vendor/datatables-extensions/FixedHeader/css/fixedHeader.dataTables.css, vendor/datatables-extensions/Responsive/css/responsive.dataTables.min.css, vendor/datatables-extensions/rowgroup/css/rowGroup.dataTables.min.css #}
{#js vendor/jquery/jquery.min.js, vendor/popper/popper.min.js, vendor/bootstrap5/js/bootstrap.min.js, vendor/datatables-extensions/JSZip/jszip.min.js, vendor/datatables-extensions/pdfmake/build/pdfmake.min.js, vendor/datatables-extensions/pdfmake/build/vfs_fonts.js, vendor/datatables/js/dataTables.min.js, vendor/datatables-extensions/Responsive/js/dataTables.responsive.min.js, vendor/datatables-extensions/Buttons/js/dataTables.buttons.min.js, vendor/datatables-extensions/Buttons/js/buttons.html5.min.js, vendor/datatables-extensions/FixedHeader/js/dataTables.fixedHeader.min.js, vendor/datatables-extensions/rowgroup/js/dataTables.rowGroup.js #}
{% set classes = {
  "sPaging": "d-flex justify-content-center",
  "sPageButton": "btn btn-outline-primary ms-1 me-1",
  "sPageButtonActive": "active"
} %}
{% set language = {
  "url": url_for('language', _('en')),
  "info": info_message or (_(' from _START_ to _END_ of _TOTAL_ total') if paging else _('Showing total of _TOTAL_')),
  "emptyTable": empty_message or _('List is empty'),
} %}
{# Use jinja recursive loop to merge buttons config. #}
{% set buttons_cfg_default = {
  "dom": {
    "button": {
      "className": "btn btn-sm ms-1 mb-2 mb-sm-0",
      "active": "active"
    },
    "collection": {
      "tag": "div",
      "button": {
        "tag": "a",
        "className": "btn btn-sm btn-link mb-2 mb-sm-0 w-100 text-start",
        "active": "active",
        "disabled": "disabled"
      }
    }
  }
} %}
{% set ns = namespace(buttons_cfg = dict(buttons_cfg_default), stack_value=[]) %}
{% set ns.stack_value = [ns.buttons_cfg] %}
{% for key, value in buttons_cfg.items() recursive %}
  {% if value is mapping %}
    {% do ns.stack_value.append( ns.stack_value[-1].get(key, {}) ) %}
    {{ loop(value.items() ) }}
    {% set value = ns.stack_value.pop() %}
  {% endif %}
  {% do ns.stack_value[-1].__setitem__(key, value) %}
{% endfor %}
{% do ns.buttons_cfg.__setitem__('buttons', buttons) %}
<table {{ attrs.render(class="table table-hover",
   width="100%",
   data_ajax=data,
   data_auto_width=auto_width | tojson,
   data_buttons=ns.buttons_cfg | tojson,
   data_classes=classes | tojson,
   data_columns=columns | tojson,
   data_layout=layout | tojson,
   data_fixed_header=fixed_header | tojson,
   data_language=language | tojson,
   data_length_change=length_change | tojson,
   data_order=order | tojson | e,
   data_page_length=page_length | tojson,
   data_paging=paging | tojson,
   data_responsive=responsive | tojson,
   data_row_group=rowgroup | tojson,
   data_searching=searching | tojson,
   data_server_side=server_side | tojson,
   data_state_save=state_save | tojson,
   data_scroll_y=scroll_y) }}>
</table>
