class handler {

		constructor(startTime, startX, startY) {
			this.startTime = startTime
			this.lastX = this.startX = startX
			this.startY = startY
			this._moveFunc = this.firstMove
		}

		move({
			timeStamp,
			pageX,
			pageY
		}) {
			return this._moveFunc(timeStamp, pageX, pageY)
		}


		firstMove(timeStamp, pageX, pageY) {
			if (Math.abs(pageX - this.startX) > Math.abs(pageY - this.startY)) {
				this._moveFunc = this.nextMove
			} else {
				this._moveFunc = () => {
					return 0
				}
				this.endMove = () => {
					return {
						invalid: true
					}
				}
			}
			return 0
		}

		nextMove(timeStamp, pageX, pageY) {
			const r = pageX - this.lastX
			this.lastX = pageX
			return r
		}

		isQuick(endTime, endX) {
			return endTime - this.startTime < 200 && Math.abs(endX - this.startX) > 50
		}

		endMove(endTime, pageX, pageY) {
			return {
				invalid: false,
				quick: this.isQuick(endTime, pageX),
				dir: pageX > this.startX ? 'r' : 'l',
				move: Math.abs(pageX - this.startX)
			}
		}
	}
export default handler