import { TouchCollection } from "./touchCollection";
var typeMap = {
    touch: {
        pointerdown: "touchstart",
        pointermove: "touchmove",
        pointerup: "touchend"
    },
    mouse: {
        pointerdown: "mousedown",
        pointermove: "mousemove",
        pointerup: "mouseup"
    }
};
var OrbiterEventHandler = /** @class */ (function () {
    function OrbiterEventHandler() {
        this.touchCollection = new TouchCollection();
    }
    OrbiterEventHandler.prototype.handlePointerEvent = function (controls, event, eventType) {
        if (eventType === void 0) { eventType = event.type; }
        var pointerType = event.pointerType;
        var methodName = typeMap[pointerType][eventType];
        if (pointerType === "touch") {
            var fakeTouch = this.buildFakeTouch(event);
            return controls[methodName](fakeTouch);
        }
        return controls[methodName](event);
    };
    OrbiterEventHandler.prototype.cancelOrbiter = function (controls, event) {
        return this.handlePointerEvent(controls, event, "pointerup");
    };
    OrbiterEventHandler.prototype.buildFakeTouch = function (event) {
        this.touchCollection.handleEvent(event);
        var fakeEvent = {
            preventDefault: function () { return event.preventDefault(); },
            stopPropagation: function () { return event.stopPropagation(); },
            touches: this.touchCollection.getTouches()
        };
        return fakeEvent;
    };
    return OrbiterEventHandler;
}());
export { OrbiterEventHandler };
