/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { 
// eslint-disable-next-line @typescript-eslint/no-unused-vars
h, Host, } from "@stencil/core";
import { TeleportInteractionHandler } from "../../lib/teleportation/interactions";
import { WalkModeController } from "../../lib/walk-mode/controller";
import { WalkModeModel } from "../../lib/walk-mode/model";
/**
 * The `<vertex-viewer-teleport-tool>` allows for click-based "teleportation"
 * around a model, which is particularly useful for walking through a model.
 * This tool is automatically included as part of the <vertex-viewer-walk-mode-tool>.
 */
export class ViewerTeleportTool {
    constructor() {
        /**
         * Indicates whether animations will be used when performing camera
         * operations. Defaults to `false`.
         */
        this.animationsDisabled = false;
        /**
         * The duration of animations, in milliseconds. Defaults to `500`.
         */
        this.animationMs = 500;
        this.model = new WalkModeModel();
        this.stateMap = {};
    }
    /**
     * @ignore
     */
    componentWillLoad() {
        this.setupController();
        this.setupInteractionHandler();
        this.setDepthBuffers();
    }
    /**
     * @ignore
     */
    connectedCallback() {
        this.setupInteractionHandler();
        this.setDepthBuffers();
    }
    /**
     * @ignore
     */
    disconnectedCallback() {
        this.clearInteractionHandler();
        this.resetDepthBuffers();
    }
    /**
     * @ignore
     */
    handleModeChange() {
        var _a;
        (_a = this.controller) === null || _a === void 0 ? void 0 : _a.setTeleportMode(this.mode);
        if (this.mode != null) {
            this.setDepthBuffers();
        }
        else {
            this.resetDepthBuffers();
        }
    }
    /**
     * @ignore
     */
    handleViewerChanged() {
        this.clearInteractionHandler();
        this.setupInteractionHandler();
        this.setDepthBuffers();
    }
    /**
     * @ignore
     */
    handleAnimationMsChanged() {
        var _a;
        if (this.animationMs != null) {
            (_a = this.interactionHandler) === null || _a === void 0 ? void 0 : _a.setAnimations({ durationMs: this.animationMs });
        }
    }
    /**
     * @ignore
     */
    handleAnimationsDisabledChanged() {
        var _a, _b;
        if (this.animationsDisabled) {
            (_a = this.interactionHandler) === null || _a === void 0 ? void 0 : _a.setAnimations(undefined);
        }
        else if (this.animationMs != null) {
            (_b = this.interactionHandler) === null || _b === void 0 ? void 0 : _b.setAnimations({ durationMs: this.animationMs });
        }
    }
    /**
     * @ignore
     */
    handleControllerChanged() {
        this.setupInteractionHandler();
        this.setupController();
        this.controllerChanged.emit(this.controller);
    }
    handleModelChanged() {
        this.setupController();
        this.clearInteractionHandler();
        this.setupInteractionHandler();
    }
    render() {
        return h(Host, { key: 'c8a6512176d203d38ae647ccddcfa8adf307f977' });
    }
    setupController() {
        if (this.controller == null) {
            this.controller = new WalkModeController(this.model);
            this.controller.setTeleportMode(this.mode);
            this.controllerChanged.emit(this.controller);
        }
        else {
            this.controller.setTeleportMode(this.mode);
            this.controller.updateModel(this.model);
        }
    }
    setDepthBuffers() {
        if (this.mode != null &&
            this.viewer != null &&
            this.viewer.depthBuffers == null) {
            this.stateMap.shouldClearDepthBuffers = true;
            this.viewer.depthBuffers = 'final';
        }
    }
    resetDepthBuffers() {
        if (this.stateMap.shouldClearDepthBuffers && this.viewer != null) {
            this.viewer.depthBuffers = undefined;
            this.stateMap.shouldClearDepthBuffers = undefined;
        }
    }
    clearInteractionHandler() {
        var _a, _b;
        (_a = this.interactionHandlerDisposable) === null || _a === void 0 ? void 0 : _a.dispose();
        this.interactionHandlerDisposable = undefined;
        (_b = this.interactionHandler) === null || _b === void 0 ? void 0 : _b.dispose();
        this.interactionHandler = undefined;
    }
    async setupInteractionHandler() {
        var _a;
        if (this.interactionHandler == null) {
            this.interactionHandler = new TeleportInteractionHandler(this.model, !this.animationsDisabled && this.animationMs != null
                ? { durationMs: this.animationMs }
                : undefined);
            this.interactionHandlerDisposable =
                await ((_a = this.viewer) === null || _a === void 0 ? void 0 : _a.registerInteractionHandler(this.interactionHandler));
        }
    }
    static get is() { return "vertex-viewer-teleport-tool"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["viewer-teleport-tool.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["viewer-teleport-tool.css"]
        };
    }
    static get properties() {
        return {
            "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
            },
            "mode": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "ViewerTeleportMode",
                    "resolved": "\"teleport\" | \"teleport-and-align\" | \"teleport-toward\" | undefined",
                    "references": {
                        "ViewerTeleportMode": {
                            "location": "import",
                            "path": "../../lib/walk-mode/model",
                            "id": "src/lib/walk-mode/model.ts::ViewerTeleportMode",
                            "referenceLocation": "ViewerTeleportMode"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The type of teleportation to perform when clicking.\n\n`teleport` - the camera's `position` is moved to the location of the hit result\nconstrained by the plane represented by the camera's current `position` and `up`\nvectors.\n\n`teleport-and-align` - the camera's `position`, `lookAt`, and `up` vectors are updated\nto align to the plane represented by the hit result's position and normal.\n\n`teleport-toward` - the camera's `position` is moved a fixed distance toward the location of the\nhit result constrained by the plane represented by the camera's current `position` and `up`\nvectors.\n\n`undefined` - no teleportation will occur when clicking.\n\nDefaults to `undefined`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "mode"
            },
            "animationsDisabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Indicates whether animations will be used when performing camera\noperations. Defaults to `false`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "animations-disabled",
                "defaultValue": "false"
            },
            "animationMs": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number | undefined",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The duration of animations, in milliseconds. Defaults to `500`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "animation-ms",
                "defaultValue": "500"
            },
            "controller": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "WalkModeController",
                    "resolved": "WalkModeController | undefined",
                    "references": {
                        "WalkModeController": {
                            "location": "import",
                            "path": "../../lib/walk-mode/controller",
                            "id": "src/lib/walk-mode/controller.ts::WalkModeController",
                            "referenceLocation": "WalkModeController"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "model": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "WalkModeModel",
                    "resolved": "WalkModeModel",
                    "references": {
                        "WalkModeModel": {
                            "location": "import",
                            "path": "../../lib/walk-mode/model",
                            "id": "src/lib/walk-mode/model.ts::WalkModeModel",
                            "referenceLocation": "WalkModeModel"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "new WalkModeModel()"
            }
        };
    }
    static get events() {
        return [{
                "method": "controllerChanged",
                "name": "controllerChanged",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event emitted when the `WalkModeController` associated with this tool changes."
                },
                "complexType": {
                    "original": "WalkModeController",
                    "resolved": "WalkModeController",
                    "references": {
                        "WalkModeController": {
                            "location": "import",
                            "path": "../../lib/walk-mode/controller",
                            "id": "src/lib/walk-mode/controller.ts::WalkModeController",
                            "referenceLocation": "WalkModeController"
                        }
                    }
                }
            }];
    }
    static get watchers() {
        return [{
                "propName": "mode",
                "methodName": "handleModeChange"
            }, {
                "propName": "viewer",
                "methodName": "handleViewerChanged"
            }, {
                "propName": "animationMs",
                "methodName": "handleAnimationMsChanged"
            }, {
                "propName": "animationsDisabled",
                "methodName": "handleAnimationsDisabledChanged"
            }, {
                "propName": "controller",
                "methodName": "handleControllerChanged"
            }, {
                "propName": "model",
                "methodName": "handleModelChanged"
            }];
    }
}
//# sourceMappingURL=viewer-teleport-tool.js.map
