/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Point } from "@vertexvis/geometry";
import { PanInteraction, PivotInteraction, RotateInteraction, RotatePointInteraction, TwistInteraction, ZoomInteraction, } from "./mouseInteractions";
import { MultiElementInteractionHandler } from "./multiElementInteractionHandler";
export class PointerInteractionHandler extends MultiElementInteractionHandler {
    constructor(getConfig, rotateInteraction = new RotateInteraction(), rotatePointInteraction = new RotatePointInteraction(), zoomInteraction = new ZoomInteraction(() => getConfig().interactions), panInteraction = new PanInteraction(), twistInteraction = new TwistInteraction(), pivotInteraction = new PivotInteraction()) {
        super('pointerdown', 'pointerup', 'pointermove', rotateInteraction, rotatePointInteraction, zoomInteraction, panInteraction, twistInteraction, pivotInteraction, getConfig);
        this.touchPoints = new Set();
        this.handlePointerDown = this.handlePointerDown.bind(this);
        this.handlePointerUp = this.handlePointerUp.bind(this);
    }
    initialize(element, api) {
        super.initialize(element, api);
        element.addEventListener('pointerdown', this.handlePointerDown);
    }
    addEventListenersToElement(element) {
        element.addEventListener(this.downEvent, this.handleDownEvent);
        element.addEventListener('wheel', this.handleMouseWheel, {
            passive: false,
        });
        return {
            dispose: () => {
                element.removeEventListener(this.downEvent, this.handleDownEvent);
                element.removeEventListener('wheel', this.handleMouseWheel);
            },
        };
    }
    handlePointerDown(event) {
        this.downPosition = Point.create(event.screenX, event.screenY);
        this.touchPoints.add(event.pointerId);
        if (this.touchPoints.size === 1) {
            window.addEventListener('pointerup', this.handlePointerUp);
        }
        if (this.touchPoints.size === 2) {
            this.disableIndividualInteractions = true;
        }
    }
    handlePointerUp(event) {
        this.touchPoints.delete(event.pointerId);
        if (this.touchPoints.size < 2) {
            this.disableIndividualInteractions = false;
        }
        if (this.touchPoints.size === 0) {
            window.removeEventListener('pointerup', this.handlePointerUp);
        }
    }
}
//# sourceMappingURL=pointerInteractionHandler.js.map
