/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { h, Host } from "@stencil/core";
import { SceneViewAPIClient } from "@vertexvis/scene-view-protos/sceneview/protos/scene_view_api_pb_service";
import { parseAndValidateConfig } from "../../lib/config";
import { MeasurementController, MeasurementModel, MeasurementOverlayManager, } from "../../lib/measurement";
import { MeasurementInteractionHandler } from "../../lib/measurement/interactions";
import { EntityType } from "../../lib/types";
export class ViewerMeasurementPrecise {
    constructor() {
        /**
         * The model that contains the entities and outcomes from performing precise
         * measurements.
         */
        this.measurementModel = new MeasurementModel();
        /**
         * The manager that is responsible for measurement overlays to present by this
         * component.
         */
        this.measurementOverlays = new MeasurementOverlayManager();
        /**
         * @internal
         *
         * An internal property that can be used to opt-in to performing measurements
         * on other types of entities.
         */
        this.measurableEntityTypes = [
            EntityType.PRECISE_SURFACE,
            EntityType.IMPRECISE_SURFACE,
        ];
        /**
         * The environment that will be used to request measurement results.
         */
        this.configEnv = 'platprod';
    }
    /**
     * @ignore
     */
    connectedCallback() {
        this.setupInteractionHandler();
    }
    /**
     * @ignore
     */
    componentWillLoad() {
        this.setupController();
        this.setupInteractionHandler();
    }
    /**
     * @ignore
     */
    disconnectedCallback() {
        this.clearInteractionHandler();
    }
    /**
     * @ignore
     */
    handleMeasurableEntityTypesChanged() {
        this.setupInteractionHandler();
    }
    /**
     * @ignore
     */
    handleMeasurementControllerChanged() {
        this.setupInteractionHandler();
    }
    /**
     * @ignore
     */
    handleMeasurementModelChanged() {
        this.setupController();
    }
    /**
     * @ignore
     */
    handleViewerChanged() {
        this.setupInteractionHandler();
    }
    /**
     * @ignore
     */
    render() {
        return (h(Host, { key: '2113569601821e742598eae47086b8bbd9198257' }, h("vertex-viewer-measurement-overlays", { key: 'd5ad40dd490ee2f6e1bddf5190c08907d706e0b9', viewer: this.viewer, measurementOverlays: this.measurementOverlays })));
    }
    setupController() {
        var _a;
        const config = parseAndValidateConfig(this.configEnv, this.config);
        const client = new SceneViewAPIClient(config.network.sceneViewHost);
        this.measurementController = new MeasurementController(this.measurementModel, client, () => { var _a; return (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.token; }, (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.deviceId);
    }
    clearInteractionHandler() {
        var _a;
        (_a = this.registeredInteractionHandler) === null || _a === void 0 ? void 0 : _a.then((handler) => handler.dispose());
        this.registeredInteractionHandler = undefined;
    }
    setupInteractionHandler() {
        var _a;
        this.clearInteractionHandler();
        if (this.measurementController != null) {
            this.registeredInteractionHandler =
                (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.registerInteractionHandler(new MeasurementInteractionHandler(this.measurementController, this.measurableEntityTypes));
        }
    }
    static get is() { return "vertex-viewer-measurement-precise"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["viewer-measurement-precise.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["viewer-measurement-precise.css"]
        };
    }
    static get properties() {
        return {
            "measurementModel": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "MeasurementModel",
                    "resolved": "MeasurementModel",
                    "references": {
                        "MeasurementModel": {
                            "location": "import",
                            "path": "../../lib/measurement",
                            "id": "src/lib/measurement/index.ts::MeasurementModel",
                            "referenceLocation": "MeasurementModel"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The model that contains the entities and outcomes from performing precise\nmeasurements."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "new MeasurementModel()"
            },
            "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 manager that is responsible for measurement overlays to present by this\ncomponent."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "new MeasurementOverlayManager()"
            },
            "measurementController": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "MeasurementController",
                    "resolved": "MeasurementController | undefined",
                    "references": {
                        "MeasurementController": {
                            "location": "import",
                            "path": "../../lib/measurement",
                            "id": "src/lib/measurement/index.ts::MeasurementController",
                            "referenceLocation": "MeasurementController"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The controller that is responsible for performing measurements and updating\nthe model."
                },
                "getter": false,
                "setter": false
            },
            "measurableEntityTypes": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "EntityType[]",
                    "resolved": "EntityType[]",
                    "references": {
                        "EntityType": {
                            "location": "import",
                            "path": "../../lib/types",
                            "id": "src/lib/types/index.ts::EntityType",
                            "referenceLocation": "EntityType"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": "An internal property that can be used to opt-in to performing measurements\non other types of entities."
                        }],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[\n    EntityType.PRECISE_SURFACE,\n    EntityType.IMPRECISE_SURFACE,\n  ]"
            },
            "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. This is automatically assigned\nif added to the light-dom of a parent viewer element."
                },
                "getter": false,
                "setter": false
            },
            "configEnv": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "Environment",
                    "resolved": "\"platdev\" | \"platprod\" | \"platstaging\"",
                    "references": {
                        "Environment": {
                            "location": "import",
                            "path": "../../lib/environment",
                            "id": "src/lib/environment.ts::Environment",
                            "referenceLocation": "Environment"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The environment that will be used to request measurement results."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "config-env",
                "defaultValue": "'platprod'"
            },
            "config": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "PartialConfig | string",
                    "resolved": "Config | string | undefined",
                    "references": {
                        "PartialConfig": {
                            "location": "import",
                            "path": "../../lib/config",
                            "id": "src/lib/config.ts::PartialConfig",
                            "referenceLocation": "PartialConfig"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "An optional configuration to setup network configuration of measurement\nendpoints."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "config"
            }
        };
    }
    static get watchers() {
        return [{
                "propName": "measurableEntityTypes",
                "methodName": "handleMeasurableEntityTypesChanged"
            }, {
                "propName": "measurementController",
                "methodName": "handleMeasurementControllerChanged"
            }, {
                "propName": "measurementModel",
                "methodName": "handleMeasurementModelChanged"
            }, {
                "propName": "viewer",
                "methodName": "handleViewerChanged"
            }];
    }
}
//# sourceMappingURL=viewer-measurement-precise.js.map
