export default function(G6) {
  G6.registerBehavior('deleteItem', {
    getEvents() {
      return {
        'keydown': 'onKeydown',
        'canvas:mouseleave': 'onCanvasLeave',
        'canvas:mouseenter': 'onCanvasFocus'
      }
    },
    onKeydown(e, env) {
      const items = this.graph.get('selectedItems')
      // const focus = this.graph.get('focusGraphWrapper')
      // console.log(items, e, focus, this.graph, 'ini')
      // 下
      if (e.keyCode === 40 && items && items.length > 0) {
        if (this.graph.executeCommand) {
          this.graph.executeCommand('toDown')
        } else {
          this.graph.toUp(items[0])
        }
      }
      // 上
      if (e.keyCode === 38 && items && items.length > 0) {
        if (this.graph.executeCommand) {
          this.graph.executeCommand('toUp')
        } else {
          this.graph.toUp(items[0])
        }
      }
      // 左
      if (e.keyCode === 37 && items && items.length > 0) {
        if (this.graph.executeCommand) {
          this.graph.executeCommand('toLeft')
        } else {
          this.graph.toUp(items[0])
        }
      }
      // 右
      if (e.keyCode === 39 && items && items.length > 0) {
        if (this.graph.executeCommand) {
          this.graph.executeCommand('toRight')
        } else {
          this.graph.toUp(items[0])
        }
      }
      // if (e.keyCode === 46 && items && items.length > 0 && focus) {
      //   if (this.graph.executeCommand) {
      //     this.graph.executeCommand('delete', {})
      //   } else {
      //     this.graph.remove(items[0])
      //   }
      //   this.graph.set('selectedItems', [])
      //   this.graph.emit('afteritemselected', [])
      // }
    },
    onCanvasLeave(e) {
      this.graph.set('focusGraphWrapper', false)
    },
    onCanvasFocus() {
      this.graph.set('focusGraphWrapper', true)
    }
  })
}
