const Store = require('electron-store')
const localStore = new Store()

export default function (e, vue) {
  if (!localStore.get('quickSupport')) return

  let confirmComponent = vue.$refs.orderInfo.$refs.confirm

  switch (e.code) {
    case 'F1':
      vue.$refs.formInfo.setFocus()
      break
    case 'F2':
      vue.$refs.ticketList.setFocus()
      break
    case 'Delete':
      if (e.ctrlKey && !confirmComponent.visible && vue.orderItems.length) {
        console.log('清空订单')
        vue.orderItems = []
        vue.$refs.formInfo.form.count = 1
      }
      break
    case 'PageUp':
      vue.$refs.orderInfo.PageUp()
      confirmComponent.arrowUp()
      break
    case 'PageDown':
      vue.$refs.orderInfo.PageDown()
      confirmComponent.arrowDown()
      break
    case 'ArrowUp':
      if (confirmComponent.visible) {
        confirmComponent.arrowUp()
      } else {
        vue.$refs.ticketList.arrowUp()
      }
      break
    case 'ArrowDown':
      if (confirmComponent.visible) {
        confirmComponent.arrowDown()
      } else {
        vue.$refs.ticketList.arrowDown()
      }
      break
    case 'NumpadEnter':
    case 'Enter':
      if (confirmComponent.visible) {
        e.preventDefault()
        e.stopPropagation()
        if (confirmComponent.submitDisable) return
        confirmComponent.submit()
        return
      }
      if (e.ctrlKey) {
        if (vue.orderItems.length) {
          vue.$refs.orderInfo.handleConfirm()
        } else {
          vue.$message.error('请添加票种')
        }
      } else {
        vue.$refs.formInfo.addToOrder()
      }

      break
  }

  e.preventDefault()
  e.stopPropagation()
}
