<template>
  <div>
    <gz-data-table
      formKey="adm-history"
      :dataListKey="dataListKey"
      :dataListFilter="dataListFilter"
      :dataListSort="dataListSort"
      :showSelect="false"
      :singleSelect="false"
      :reload="reload"
      v-on:selection-change="handleSelected"
      data-cy="historyTable"
    >
    </gz-data-table>
  </div>
</template>

<script>
const FORM_KEY = "adm-history";
export default {
  async created() {
    this.rights = window.$gz.role.getRights(window.$gz.type.Global);
    window.$gz.eventBus.$on("menu-click", clickHandler);
    //await fetchTranslatedText(this);
    generateMenu(this);
  },
  beforeDestroy() {
    window.$gz.eventBus.$off("menu-click", clickHandler);
  },
  data() {
    return {
      uploadFiles: [],
      currentListViewId: 1,
      dataListKey: "EventDataList",
      dataListFilter: "",
      dataListSort: "",
      rights: window.$gz.role.defaultRightsObject(),
      reload: false,
      uploading: false
    };
  },
  methods: {
    handleSelected(selectedItems) {
      console.log(selectedItems);
    }
  }
};

/////////////////////////////
//
//
function clickHandler(menuItem) {
  if (!menuItem) {
    return;
  }
  let m = window.$gz.menu.parseMenuItem(menuItem);
  if (m.owner == FORM_KEY && !m.disabled) {
    switch (m.key) {
      // case "new":
      //   m.vm.$router.push({
      //     name: "adm-translation",
      //     params: { recordid: 0 }
      //   });
      //   break;
      default:
        window.$gz.eventBus.$emit(
          "notify-warning",
          FORM_KEY + "::context click: [" + m.key + "]"
        );
    }
  }
}

//////////////////////
//
//
function generateMenu(vm) {
  let menuOptions = {
    isMain: true,
    icon: "$ayiHistory",
    title: "History",
    helpUrl: "form-adm-history",
    hideSearch: true,
    menuItems: []
  };

  // //STUB REPORTS
  // //Report not Print, print is a further option
  // menuOptions.menuItems.push({
  //   title: "Report",
  //   icon: "$ayiFileAlt",
  //   key: FORM_KEY + ":report",
  //   vm: vm
  // });

  // menuOptions.menuItems.push({
  //   title: "stub: Last report used",
  //   icon: "$ayiFileAlt",
  //   key: FORM_KEY + ":report:STUBlastusedreportid",
  //   vm: vm
  // });

  window.$gz.eventBus.$emit("menu-change", menuOptions);
}

// //////////////////////////////////////////////////////////
// //
// // Ensures UI translated text is available
// //
// async function fetchTranslatedText(vm) {
//   await window.$gz.translation.cacheTranslations(["ReadOnly"]);
// }
</script>
