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

export default function (e, vue) {
  if (!localStore.get('quickSupport')) return
  console.log(e.code)
  let confirmComponent = vue.$refs.orderInfo.$refs.confirm

  switch (e.code) {
    case 'F1':
      vue.$refs.formInfo.setFocus()
      e.preventDefault()
      break
    case 'F2':
      vue.$refs.ticketList.setFocus()
      e.preventDefault()
      break
    case 'Delete':
      if (e.ctrlKey && !confirmComponent.visible && vue.orderItems.length) {
        console.log('清空订单')
        vue.orderItems = []
        vue.$refs.formInfo.form.count = 1
      }
      e.preventDefault()
      break
    case 'PageUp':
      vue.$refs.orderInfo.PageUp()
      confirmComponent.arrowUp()
      e.preventDefault()
      break
    case 'PageDown':
      vue.$refs.orderInfo.PageDown()
      confirmComponent.arrowDown()
      e.preventDefault()
      break
    case 'ArrowUp':
      if (confirmComponent.visible) {
        confirmComponent.arrowUp()
      } else {
        vue.$refs.ticketList.arrowUp()
      }
      e.preventDefault()
      break
    case 'ArrowDown':
      if (confirmComponent.visible) {
        confirmComponent.arrowDown()
      } else {
        vue.$refs.ticketList.arrowDown()
      }
      e.preventDefault()
      break
    case 'NumpadEnter':
    case 'Enter':
      if (confirmComponent.visible) {
        e.preventDefault()
        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()
      }
      e.preventDefault()
      break
  }
}
