import { defineStore } from "pinia";

export const useContextMenuStore = defineStore("context-menu", {
  state: () => {
    return {
      contextX: 0,
      contextY: 0,
      show: false,
      component_ref: null as any,
      data: null as any,
    };
  },
  getters: {
    contextMenuStyle: (state) => {
      return `left: ${state.contextX}px; top: ${state.contextY}px`;
    },
  },
  actions: {
    openContextMenu(e: MouseEvent, content: { component_ref: any; data: any }) {
      this.component_ref = content.component_ref;
      this.data = content.data;
      this.contextX = e.pageX;
      this.contextY = e.pageY;
      this.show = true;
    },
    closeContextMenu() {
      this.component_ref = null;
      this.data = null;
      this.show = false;
    },
  },
});
