import Vue from 'vue';

var MIN_DISTANCE = 10;

function getDirection(x, y) {
    if (x > y && x > MIN_DISTANCE) {
        return 'horizontal';
    }

    if (y > x && y > MIN_DISTANCE) {
        return 'vertical';
    }

    return '';
}

export var MouseMixin = Vue.extend({
    data: function data() {
        return {
            direction: ''
        };
    },


    methods: {
        mouseStart: function mouseStart(event) {
            this.resetMouseStatus();
            this.startX = event.clientX;
            this.startY = event.clientY;
        },
        mouseMove: function mouseMove(event) {
            this.deltaX = event.clientX - this.startX;
            this.deltaY = event.clientY - this.startY;
            this.offsetX = Math.abs(this.deltaX);
            this.offsetY = Math.abs(this.deltaY);
            this.direction = this.direction || getDirection(this.offsetX, this.offsetY);
        },
        resetMouseStatus: function resetMouseStatus() {
            this.direction = '';
            this.deltaX = 0;
            this.deltaY = 0;
            this.offsetX = 0;
            this.offsetY = 0;
        }
    }
});