/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
/* eslint-disable @typescript-eslint/member-ordering */
import { h, Host } from "@stencil/core";
import { MeasurementOverlayManager, } from "../../lib/measurement";
import { MeasurementOverlayView } from "./viewer-measurement-overlays-components";
export class ViewerMeasurementOverlays {
    constructor() {
        /**
         * The model that contains the overlays to present.
         */
        this.measurementOverlays = new MeasurementOverlayManager();
        this.overlays = [];
        this.updateCamera = () => {
            var _a, _b;
            this.camera = (_b = (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.frame) === null || _b === void 0 ? void 0 : _b.scene.camera;
        };
    }
    /**
     * @ignore
     */
    handleMeasurementOverlaysChanged() {
        this.removeModelListeners();
        this.addModelListeners();
        this.updateOverlays();
    }
    /**
     * @ignore
     */
    handleViewerChanged(newViewer, oldViewer) {
        this.removeViewerListeners(oldViewer);
        this.addViewerListeners();
        this.updateCamera();
    }
    /**
     * @ignore
     */
    componentWillLoad() {
        this.addModelListeners();
        this.addViewerListeners();
        this.updateOverlays();
        this.updateCamera();
    }
    addModelListeners() {
        this.onOverlaysChangedListener = this.measurementOverlays.onOverlaysChanged(() => this.updateOverlays());
    }
    removeModelListeners() {
        var _a;
        (_a = this.onOverlaysChangedListener) === null || _a === void 0 ? void 0 : _a.dispose();
        this.onOverlaysChangedListener = undefined;
    }
    addViewerListeners() {
        var _a;
        (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.addEventListener('frameReceived', this.updateCamera);
    }
    removeViewerListeners(viewer) {
        viewer === null || viewer === void 0 ? void 0 : viewer.removeEventListener('frameReceived', this.updateCamera);
    }
    updateOverlays() {
        this.overlays = this.measurementOverlays.getOverlays();
    }
    /**
     * @ignore
     */
    render() {
        return (h(Host, { key: 'fbda189899fa87c57b11615693d1319eee341fea' }, this.overlays.map((overlay) => {
            if (this.camera != null && this.viewer != null) {
                return (h(MeasurementOverlayView, { overlay: overlay, viewport: this.viewer.viewport, camera: this.camera }));
            }
        })));
    }
    static get is() { return "vertex-viewer-measurement-overlays"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["viewer-measurement-overlays.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["viewer-measurement-overlays.css"]
        };
    }
    static get properties() {
        return {
            "measurementOverlays": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "MeasurementOverlayManager",
                    "resolved": "MeasurementOverlayManager",
                    "references": {
                        "MeasurementOverlayManager": {
                            "location": "import",
                            "path": "../../lib/measurement",
                            "id": "src/lib/measurement/index.ts::MeasurementOverlayManager",
                            "referenceLocation": "MeasurementOverlayManager"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The model that contains the overlays to present."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "new MeasurementOverlayManager()"
            },
            "camera": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "FrameCameraBase",
                    "resolved": "FrameCameraBase | undefined",
                    "references": {
                        "FrameCameraBase": {
                            "location": "import",
                            "path": "../../lib/types",
                            "id": "src/lib/types/index.ts::FrameCameraBase",
                            "referenceLocation": "FrameCameraBase"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": undefined
                        }],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "viewer": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "HTMLVertexViewerElement",
                    "resolved": "HTMLVertexViewerElement | undefined",
                    "references": {
                        "HTMLVertexViewerElement": {
                            "location": "global",
                            "id": "global::HTMLVertexViewerElement"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The viewer that this component is bound to."
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get states() {
        return {
            "overlays": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "measurementOverlays",
                "methodName": "handleMeasurementOverlaysChanged"
            }, {
                "propName": "viewer",
                "methodName": "handleViewerChanged"
            }];
    }
}
//# sourceMappingURL=viewer-measurement-overlays.js.map
