import { reactive } from 'vue'
import type { ContextMenuInfoType, IContextMenu } from './types'
import { getSystemShortcutKeyName } from '../utils'

const systemShortcutKey = getSystemShortcutKeyName()

export const contextMenuStore: IContextMenu = reactive({
  menuInfo: {
    display: false,
    left: 0,
    top: 0,
    info: {
      selectAll: {
        title: '全选',
        hot_key: `${systemShortcutKey} + A`,
        enable: false
      },
      copy: {
        title: '复制',
        hot_key: `${systemShortcutKey} + C`,
        enable: false
      },
      paste: {
        title: '粘贴',
        hot_key: `${systemShortcutKey} + V`,
        enable: false
      },
      delete: {
        title: '删除',
        hot_key: 'Delete',
        enable: false
      },
      group: {
        title: '组合',
        hot_key: `${systemShortcutKey} + G`,
        enable: false
      },
      ungroup: {
        title: '取消组合',
        hot_key: `${systemShortcutKey} + U`,
        enable: false
      },
      moveTop: {
        title: '置顶',
        hot_key: `${systemShortcutKey} + Right`,
        enable: false
      },
      moveUp: {
        title: '上移',
        hot_key: `${systemShortcutKey} + Up`,
        enable: false
      },
      moveDown: {
        title: '下移',
        hot_key: `${systemShortcutKey} + Down`,
        enable: false
      },
      moveBottom: {
        title: '置底',
        hot_key: `${systemShortcutKey} + Left`,
        enable: false
      }
    }
  },
  setMenuInfo: (val: IContextMenu['menuInfo']) => {
    contextMenuStore.menuInfo = val
  },
  setDisplayItem: (val: ContextMenuInfoType[]) => {
    for (const key in contextMenuStore.menuInfo.info) {
      contextMenuStore.menuInfo.info[key as ContextMenuInfoType].enable = false
    }
    val.forEach((f) => {
      contextMenuStore.menuInfo.info[f].enable = true
    })
  }
})
