<template>
  <div>
    <gz-data-table
      ref="gzdatatable"
      form-key="ops-notify-log"
      :rid-column-openable="false"
      :do-not-truncate="true"
      data-list-key="NotificationDeliveryLogDataList"
      :show-select="false"
      :reload="reload"
      data-cy="notifyLogTable"
      @selection-change="handleSelected"
    >
    </gz-data-table>
  </div>
</template>
<script>
const FORM_KEY = "ops-notify-log";
export default {
  data() {
    return {
      rights: window.$gz.role.defaultRightsObject(),
      aType: window.$gz.type.OpsNotificationSettings,
      selectedItems: [],
      reload: false
    };
  },
  created() {
    this.rights = window.$gz.role.getRights(
      window.$gz.type.OpsNotificationSettings
    );
    window.$gz.eventBus.$on("menu-click", clickHandler);
    generateMenu(this);
  },
  beforeDestroy() {
    window.$gz.eventBus.$off("menu-click", clickHandler);
  },
  methods: {
    handleSelected(selected) {
      this.selectedItems = selected;
    }
  }
};

/////////////////////////////
//
//
async function clickHandler(menuItem) {
  if (!menuItem) {
    return;
  }
  const 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 + "]"
        );
    }
  }
}

//////////////////////
//
//
function generateMenu() {
  const menuOptions = {
    isMain: true,
    icon: "$ayiHistory",
    title: "NotificationDeliveryLog",
    helpUrl: "ops-notify-log",
    menuItems: []
  };

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