(function(factory) {
  typeof define === "function" && define.amd ? define(factory) : factory();
})((function() {
  "use strict";
  const initDataTables = () => {
    if ("undefined" === typeof jQuery.fn.dataTable) {
      return false;
    }
    document.querySelectorAll(".anwp-sl-game-player-stats").forEach((el) => {
      if (!el.classList.contains("dataTable")) {
        const tableArgs = {
          scrollX: true,
          paging: false,
          searching: false,
          info: false,
          order: [],
          columnDefs: [
            { targets: "no-sort", orderable: false }
          ],
          fixedColumns: {
            leftColumns: 1
          },
          language: {
            emptyTable: "No data"
          }
        };
        new DataTable(el, tableArgs);
      }
    });
    document.querySelectorAll(".anwp-sl-team-players-stats").forEach((el) => {
      if (!el.classList.contains("dataTable")) {
        const tableArgs = {
          scrollX: true,
          paging: false,
          searching: false,
          info: false,
          order: [],
          columnDefs: [
            { targets: "no-sort", orderable: false }
          ],
          fixedColumns: {
            leftColumns: 1
          },
          language: {
            emptyTable: "No data"
          }
        };
        new DataTable(el, tableArgs);
      }
    });
    document.querySelectorAll(".anwp-sl-player-stats").forEach((el) => {
      if (!el.classList.contains("dataTable")) {
        const tableArgs = {
          scrollX: true,
          paging: false,
          searching: false,
          info: false,
          order: [],
          columnDefs: [
            { targets: "no-sort", orderable: false }
          ],
          fixedColumns: {
            leftColumns: 2
          },
          language: {
            emptyTable: "No data"
          }
        };
        const tablePlayerStats = new DataTable(el, tableArgs);
        tablePlayerStats.on("draw", () => {
          window.anwpSLHooks.doAction("do.initTooltips");
        });
      }
    });
    if (!("ResizeObserver" in window)) {
      return;
    }
    const observer = new ResizeObserver((entries) => {
      entries.forEach(() => {
        setTimeout(() => jQuery.fn.dataTable.tables({ visible: true, api: true }).columns.adjust(), 1);
      });
    });
    Array.from(document.querySelectorAll(".anwp-sl-player-stats")).forEach((el) => observer.observe(el));
    Array.from(document.querySelectorAll(".anwp-sl-team-players-stats")).forEach((el) => observer.observe(el));
    Array.from(document.querySelectorAll(".anwp-sl-game-player-stats")).forEach((el) => observer.observe(el));
  };
  const anwpSLDTLoaded = () => {
    initDataTables();
    setTimeout(() => {
      if (window.anwpSLHooks) {
        window.anwpSLHooks.addAction("on.playerStats.updated", "anwp-sl", initDataTables);
      }
    }, 5e3);
  };
  if ("loading" !== document.readyState) {
    anwpSLDTLoaded();
  } else {
    document.addEventListener("DOMContentLoaded", anwpSLDTLoaded);
  }
}));
