/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Point } from "@vertexvis/geometry";
import { MultiTouchInteractionHandler } from "./multiTouchInteractionHandler";
export class MultiPointerInteractionHandler extends MultiTouchInteractionHandler {
    constructor() {
        super();
        this.touchPoints = {};
        this.handlePointerDown = this.handlePointerDown.bind(this);
        this.handlePointerMove = this.handlePointerMove.bind(this);
        this.handlePointerUp = this.handlePointerUp.bind(this);
    }
    dispose() {
        var _a;
        (_a = this.element) === null || _a === void 0 ? void 0 : _a.removeEventListener('pointerdown', this.handlePointerDown);
        super.dispose();
    }
    initialize(element, api) {
        super.initialize(element, api);
        element.addEventListener('pointerdown', this.handlePointerDown);
    }
    handlePointerDown(event) {
        const point = Point.create(event.screenX, event.screenY);
        this.touchPoints = {
            ...this.touchPoints,
            [event.pointerId]: point,
        };
        const keys = Object.keys(this.touchPoints);
        if (keys.length === 1) {
            window.addEventListener('pointermove', this.handlePointerMove);
            window.addEventListener('pointerup', this.handlePointerUp);
        }
        else if (keys.length === 2) {
            this.beginTwoPointTouch(this.touchPoints[0], this.touchPoints[1]);
        }
    }
    handlePointerMove(event) {
        if (this.touchPoints[event.pointerId] != null) {
            this.touchPoints[event.pointerId] = Point.create(event.screenX, event.screenY);
        }
        const keys = Object.keys(this.touchPoints);
        if (keys.length === 2) {
            const point1 = this.touchPoints[keys[0]];
            const point2 = this.touchPoints[keys[1]];
            this.handleTwoPointTouchMove(point1, point2);
        }
    }
    handlePointerUp(event) {
        var _a;
        delete this.touchPoints[event.pointerId];
        const keys = Object.keys(this.touchPoints);
        if (keys.length === 1) {
            (_a = this.interactionApi) === null || _a === void 0 ? void 0 : _a.endInteraction();
        }
        if (keys.length === 0) {
            window.removeEventListener('pointermove', this.handlePointerMove);
            window.removeEventListener('pointerup', this.handlePointerUp);
        }
        this.endTwoPointTouch();
    }
}
//# sourceMappingURL=multiPointerInteractionHandler.js.map
