import {noop} from "../../../../core/function/noop.js";

export class DragHandler {
    /**
     *
     * @param {function} [dragStart=noop]
     * @param {(position:Vector2,delta:Vector2)=>*} [drag=noop]
     * @param {function} [dragEnd=noop]
     */
    constructor({dragStart = noop, drag = noop, dragEnd = noop}) {
        this.dragStartCallback = dragStart;
        this.dragCallback = drag;
        this.dragEndCallback = dragEnd;

        this.active = false;
    }

    start(position) {
        this.active = true;
        this.dragStartCallback(position);
    }

    drag(position, delta) {
        if (!this.active) return;

        this.dragCallback(position, delta);
    }

    end(position) {
        if (!this.active) return;

        this.active = false;
        this.dragEndCallback(position);
    }
}
