<template>
  <gz-data-table
    formKey="test-widgets"
    :dataListKey="dataListKey"
    :dataListFilter="dataListFilter"
    :dataListSort="dataListSort"
    :showSelect="false"
    :singleSelect="false"
    v-on:update:selected="handleSelected"
  >
  </gz-data-table>
</template>

<script>
import GzDataTable from "../components/gz-data-table.vue";
const FORM_KEY = "test-widgets";
export default {
  components: {
    GzDataTable
  },
  beforeCreate() {
    window.$gz.eventBus.$emit("menu-change", {
      isMain: true,
      icon: "vial",
      title: window.$gz.locale.get("WidgetList"),
      helpUrl: "form-ay-data-list-view",
      menuItems: []
    });
  },
  created() {
    window.$gz.eventBus.$on("menu-click", clickHandler);
  },
  beforeDestroy() {
    window.$gz.eventBus.$off("menu-click", clickHandler);
  },
  data() {
    return {
      currentListViewId: 1,
      dataListKey: "TestWidgetDataList",
      dataListFilter: "",
      dataListSort: ""
    };
  },
  methods: {
    handleSelected(selectedItems) {
      console.log(selectedItems);
    }
  }
};

/////////////////////////////
//
//
function clickHandler(menuItem) {
  if (!menuItem) {
    return;
  }
  var m = window.$gz.menu.parseMenuItem(menuItem);
  if (m.owner == FORM_KEY && !m.disabled) {
    switch (m.key) {
      default:
        window.$gz.eventBus.$emit(
          "notify-warning",
          FORM_KEY + "::context click: [" + m.key + "]"
        );
    }
  }
}
</script>
