import { observable, action } from "mobx";

class tableCtxMenuStore {
  /** 右键菜单位置 */
  @observable position = [0, ''];
  /** table的唯一id */
  @observable tableId = '';
  /** 显示菜单 */
  @observable contextMenuVisible = false;
  @action onContextMenuVisibleChange = (visible: boolean) => {
    this.contextMenuVisible = visible;
  }
  @action updatePosition = (position) => {
    this.position = position;
  }
  @action updateTableId = (tableId) => {
    this.tableId = tableId;
  }
  /** 触发显示右键菜单 */
  @action showContextMenu = (rowIndex, colName, tableId) => {
    const visible = (colName != undefined && colName != 'operation');
    /** 更新tableid，给table用做是否显示菜单（防止多表格会同时显示右键菜单） */
    this.updateTableId(tableId);
    this.updatePosition([rowIndex, colName])
    this.onContextMenuVisibleChange(visible);
  }
}

const TableCtxMenuStore = new tableCtxMenuStore();
export default TableCtxMenuStore;
