/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Vector3 } from "@vertexvis/geometry";
import { EventDispatcher, UUID } from "@vertexvis/utils";
export class MeasurementOverlayManager {
    constructor() {
        this.overlays = new Map();
        this.overlaysChanged = new EventDispatcher();
    }
    addLineFromResult(result) {
        return this.addLine(result.point1, result.point2);
    }
    addLine(start, end) {
        const id = UUID.create();
        const overlay = {
            type: 'line',
            id: id,
            start,
            end,
            dispose: () => this.remove(id),
        };
        this.addOverlay(overlay);
        return overlay;
    }
    addDistanceVectorFromResult(result) {
        return this.addDistanceVector(result.point1, result.point2);
    }
    addDistanceVector(start, end) {
        const id = UUID.create();
        const v = Vector3.subtract(start, end);
        const ye = Vector3.add(start, Vector3.create(0, -v.y, 0));
        const y = { start: start, end: ye };
        const ze = Vector3.add(ye, Vector3.create(0, 0, -v.z));
        const z = { start: ye, end: ze };
        const xe = Vector3.add(ze, Vector3.create(-v.x, 0, 0));
        const x = { start: ze, end: xe };
        const overlay = {
            type: 'distance-vector',
            id,
            x,
            y,
            z,
            dispose: () => this.remove(id),
        };
        this.addOverlay(overlay);
        return overlay;
    }
    addOverlay(overlay) {
        if (!this.overlays.has(overlay.id)) {
            this.overlays.set(overlay.id, overlay);
            this.overlaysChanged.emit(this.getOverlays());
        }
    }
    getOverlays() {
        return Array.from(this.overlays.values());
    }
    remove(id) {
        if (this.overlays.has(id)) {
            this.overlays.delete(id);
            this.overlaysChanged.emit(this.getOverlays());
            return true;
        }
        else {
            return false;
        }
    }
    onOverlaysChanged(listener) {
        return this.overlaysChanged.on(listener);
    }
}
//# sourceMappingURL=overlays.js.map
