<% content_for :javascript do %>
<script>
const SUPERTABLE_WORKER_FILE = "<%= javascript_path 'supertable3_worker' %>";
let GLOBAL_SUPERTABLE_INSTANCE = null;
</script>

<%= javascript_include_tag 'javascripts/modal_popup' %>
<%= javascript_include_tag 'javascripts/supertable3' %>
<% end %>

<%= render 'shared/supertable_controls' %>
<div class="superTable" id="tableGroups"></div>

<% content_for :post_load_javascript do %>
<script>
"use strict;"

<%= render partial: 'shared/supertable_translations', formats: [:js] %>
<%= render partial: 'shared/group_tables_common', formats: [:js] %>

const DEFAULT_COLUMNS = ["name", "abbr", "type", "members_count", "eid"];
const DEFAULT_SORTING = { column: "name", dir: ST.SortOrder.ASCENDING };

document.addEventListener("DOMContentLoaded", () => {
    modalPopup.setupGlobalEvents();

    GLOBAL_SUPERTABLE_INSTANCE = new ST.SuperTable(
        // Main container DIV
        document.getElementById("tableGroups"),

        // Settings
        {
            id: "orgGroups",
            locale: "<%= supertable_sorting_locale %>",
            csvPrefix: `<%= LdapOrganisation.current.o %>-<%= @school.cn %>-groups`,
            columnDefinitions: COLUMN_DEFINITIONS,
            columnOrder: COLUMN_ORDER,
            actions: userActions,
            openCallback: openCallback,
            massSelects: MASS_SELECTS,
            massOperations: MASS_OPERATIONS,
            massOperationsEndpoint: "<%= groups_mass_operations_path %>",
            defaultColumns: DEFAULT_COLUMNS,
            defaultSorting: DEFAULT_SORTING,
            dynamicData: "/users/<%= @school.id %>/get_school_groups_list",
        }
    );
});

</script>
<% end %>

<% content_for :page_tools do %>
<%=
toolbar do |tb|
  if @permit_group_creation
    tb.link t('link.new_group'),
            href: new_group_path(@school),
            icon: 'plus'
  end
end %>
<% end %>
