/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
/* eslint-disable @typescript-eslint/member-ordering */
import { h, Host } from "@stencil/core";
import { Vector3 } from "@vertexvis/geometry";
import { readDOM } from "../../lib/stencil";
import { FramePerspectiveCamera, Orientation, StandardView, } from "../../lib/types";
import { TriadAxis, ViewCubeCorner, ViewCubeEdge, ViewCubeShadow, ViewCubeSide, } from "./viewer-view-cube-components";
export class ViewerViewCube {
    constructor() {
        this.boxLength = 80;
        this.triadPosition = Vector3.origin();
        /**
         * The label for the side of the cube on the positive x-axis.
         */
        this.xPositiveLabel = 'Right';
        /**
         * The label for the side of the cube on the negative x-axis.
         */
        this.xNegativeLabel = 'Left';
        /**
         * The label for the side of the cube on the positive y-axis.
         */
        this.yPositiveLabel = 'Top';
        /**
         * The label for the side of the cube on the negative y-axis.
         */
        this.yNegativeLabel = 'Bottom';
        /**
         * The label for the side of the cube on the positive z-axis.
         */
        this.zPositiveLabel = 'Front';
        /**
         * The label for the side of the cube on the negative z-axis.
         */
        this.zNegativeLabel = 'Back';
        /**
         * Disables interactions for standard views.
         */
        this.standardViewsOff = false;
        /**
         * Whether to perform a `viewAll` when clicking on the view cube. If this
         * is set to `false`, the current `lookAt` point will be maintained, and the
         * camera's `position` and `up` vectors will be aligned to the standard view.
         * Defaults to `true`.
         *
         * **Note** Setting this value to `false` can result in the camera being placed
         * underneath geometry depending on the current `viewVector` length, resulting
         * in a view that may be unexpected.
         */
        this.viewAll = true;
        /**
         * The duration of the animation, in milliseconds, when a user performs a
         * standard view interaction. Set to 0 to disable animations.
         */
        this.animationDuration = 500;
        /**
         * Disables the display of the triad.
         */
        this.triadOff = false;
        /**
         * @internal
         */
        this.worldOrientation = Orientation.DEFAULT;
        this.updateMatrices = () => {
            var _a;
            if (((_a = this.viewer) === null || _a === void 0 ? void 0 : _a.frame) != null) {
                const { camera } = this.viewer.frame.scene;
                const halfLength = this.boxLength / 2;
                this.triadPosition = Vector3.create(-halfLength - 5, -halfLength - 5, -halfLength - 5);
                // Used to scale the camera position so the cube is the same size as the
                // container. This isn't exact, but pretty close.
                const lengthScalar = 3.125;
                const scale = this.boxLength * lengthScalar;
                const fovY = 21.5;
                this.camera = new FramePerspectiveCamera(Vector3.scale(scale, Vector3.negate(camera.direction)), Vector3.origin(), camera.up, 0.1, 100, 1, fovY);
                this.worldOrientation = this.viewer.frame.scene.worldOrientation;
            }
        };
    }
    handleViewerChanged(newViewer, oldViewer) {
        oldViewer === null || oldViewer === void 0 ? void 0 : oldViewer.removeEventListener('frameDrawn', this.updateMatrices);
        newViewer === null || newViewer === void 0 ? void 0 : newViewer.addEventListener('frameDrawn', this.updateMatrices);
        this.updateMatrices();
    }
    handleStandardView(standardView) {
        if (this.standardViewsOff) {
            return async () => undefined;
        }
        else {
            return async () => {
                if (this.viewer != null) {
                    const scene = await this.viewer.scene();
                    const animation = this.animationDuration > 0
                        ? { animation: { milliseconds: this.animationDuration } }
                        : {};
                    const worldStandardView = standardView.transformMatrix(this.worldOrientation.matrix);
                    // Check to see if any geometry is visible. If not, don't perform viewAll
                    const currentBoundingBox = scene.boundingBox();
                    if (!this.viewAll) {
                        scene
                            .camera()
                            .standardViewFixedLookAt(worldStandardView)
                            .render(animation);
                    }
                    else if ((currentBoundingBox === null || currentBoundingBox === void 0 ? void 0 : currentBoundingBox.max) != null &&
                        Vector3.isEqual(currentBoundingBox.max, Vector3.origin()) &&
                        Vector3.isEqual(currentBoundingBox.min, Vector3.origin())) {
                        scene.camera().standardView(worldStandardView).render(animation);
                    }
                    else {
                        scene
                            .camera()
                            .standardView(worldStandardView)
                            .viewAll()
                            .render(animation);
                    }
                }
            };
        }
    }
    /**
     * @ignore
     */
    componentWillLoad() {
        this.handleViewerChanged(this.viewer);
    }
    /**
     * @ignore
     */
    componentDidLoad() {
        if (this.rendererEl != null) {
            const observer = new ResizeObserver(() => this.handleRendererResized());
            observer.observe(this.rendererEl);
            this.handleRendererResized();
        }
    }
    handleRendererResized() {
        readDOM(() => {
            if (this.rendererEl != null) {
                const rect = this.rendererEl.getBoundingClientRect();
                this.boxLength = Math.min(rect.width, rect.height);
            }
        });
    }
    /**
     * @ignore
     */
    render() {
        return (h(Host, { key: '3e723ac47709db472f6f53e96679139fae0e3f58' }, h("vertex-viewer-dom-renderer", { key: 'f6cd68e61014aedc6978ec4590d3b8af6bacc39a', ref: (ref) => (this.rendererEl = ref), class: "renderer", camera: this.camera }, !this.triadOff && (h("vertex-viewer-dom-group", { key: '77bd1b532d5cddeffddfa933716926e4cd97d858', class: "triad", position: this.triadPosition }, h(TriadAxis, { key: 'fc954790f8b1e94a0fcbce27a877438f70f690b3', label: "X", length: this.boxLength, rotationAxis: Vector3.origin() }), h(TriadAxis, { key: '55f8abd997774fa75b59cc25ee367f97e26d8d0e', label: "Y", length: this.boxLength, rotationAxis: Vector3.back() }), h(TriadAxis, { key: '0edd14df8831e142e7b716c19195372d0ca9b540', label: "Z", length: this.boxLength, rotationAxis: Vector3.down() }))), h("vertex-viewer-dom-group", { key: '44c2aa6567000ff3a8b605bfcacff9edea99ad49', class: "cube", matrix: this.worldOrientation.matrix }, h(ViewCubeShadow, { key: '6d332b76534a1792e476d5af4c9928b655245699', length: this.boxLength + 10 }), h(ViewCubeSide, { key: 'e912dbdcfd3587e6d889b314da97d4831a5f5820', label: this.zPositiveLabel, length: this.boxLength, side: "front", onPointerDown: this.handleStandardView(StandardView.FRONT), disabled: this.standardViewsOff }), h(ViewCubeSide, { key: '9018644613e72bf4f605893e8b802e54e49d7a60', label: this.zNegativeLabel, length: this.boxLength, side: "back", onPointerDown: this.handleStandardView(StandardView.BACK), disabled: this.standardViewsOff }), h(ViewCubeSide, { key: '6f3018e38983ee92dd0d237e1f5e8d583ffc5868', label: this.xNegativeLabel, length: this.boxLength, side: "left", onPointerDown: this.handleStandardView(StandardView.LEFT), disabled: this.standardViewsOff }), h(ViewCubeSide, { key: '6ad9a228a8f08ed5834e817eb251459a2b790228', label: this.xPositiveLabel, length: this.boxLength, side: "right", onPointerDown: this.handleStandardView(StandardView.RIGHT), disabled: this.standardViewsOff }), h(ViewCubeSide, { key: '65444fe7463cc93010f697895259616e2c951185', label: this.yPositiveLabel, length: this.boxLength, side: "top", onPointerDown: this.handleStandardView(StandardView.TOP), disabled: this.standardViewsOff }), h(ViewCubeSide, { key: '69bd39a0e0c282d7699fbc43bb8162b5058b2725', label: this.yNegativeLabel, length: this.boxLength, side: "bottom", onPointerDown: this.handleStandardView(StandardView.BOTTOM), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: 'bff49b1af1febb826d2566f78f44e198e724980a', length: this.boxLength, face1Side: "top", face1Edge: "bottom", face2Side: "front", face2Edge: "top", onPointerDown: this.handleStandardView(StandardView.TOP_FRONT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: 'd218a084a54b52b791b6ee905d572fc4c5f2067e', length: this.boxLength, face1Side: "front", face1Edge: "right", face2Side: "right", face2Edge: "left", onPointerDown: this.handleStandardView(StandardView.FRONT_LEFT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '55cdc6e8ed92a5d04605648cfba59e503d74b17a', length: this.boxLength, face1Side: "bottom", face1Edge: "top", face2Side: "front", face2Edge: "bottom", onPointerDown: this.handleStandardView(StandardView.BOTTOM_FRONT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: 'e560d8a890575295b0b66391ef6edfa86a352479', length: this.boxLength, face1Side: "front", face1Edge: "left", face2Side: "left", face2Edge: "right", onPointerDown: this.handleStandardView(StandardView.FRONT_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '92175bcdb02a1ac0c69ecf060bf7ab8276bba30b', length: this.boxLength, face1Side: "top", face1Edge: "right", face2Side: "right", face2Edge: "top", onPointerDown: this.handleStandardView(StandardView.TOP_LEFT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '5c25934c6add8941aeffebf91e5d2755f736171a', length: this.boxLength, face1Side: "back", face1Edge: "left", face2Side: "right", face2Edge: "right", onPointerDown: this.handleStandardView(StandardView.BACK_LEFT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '573f648180a2ded37d05f53d54a09b594a745838', length: this.boxLength, face1Side: "bottom", face1Edge: "right", face2Side: "right", face2Edge: "bottom", onPointerDown: this.handleStandardView(StandardView.BOTTOM_LEFT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '0736e5ce0c74c217eb597d05d9cb322176c6c26e', length: this.boxLength, face1Side: "top", face1Edge: "top", face2Side: "back", face2Edge: "top", onPointerDown: this.handleStandardView(StandardView.TOP_BACK), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '2621bf73adcbdcbed213ebf1bff5c0441066dfde', length: this.boxLength, face1Side: "back", face1Edge: "right", face2Side: "left", face2Edge: "left", onPointerDown: this.handleStandardView(StandardView.BACK_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: 'a7ce12b7104292548a2f39c3c21be1bbfb741008', length: this.boxLength, face1Side: "bottom", face1Edge: "bottom", face2Side: "back", face2Edge: "bottom", onPointerDown: this.handleStandardView(StandardView.BOTTOM_BACK), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '6d51d0af13c7f6058e43d87b3b74c7f79dcd6372', length: this.boxLength, face1Side: "top", face1Edge: "left", face2Side: "left", face2Edge: "top", onPointerDown: this.handleStandardView(StandardView.TOP_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeEdge, { key: '6391a20b84bf91a6e6a8bce623fa402d02992b1b', length: this.boxLength, face1Side: "bottom", face1Edge: "left", face2Side: "left", face2Edge: "bottom", onPointerDown: this.handleStandardView(StandardView.BOTTOM_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: '119cdae569b4ac1abdc5929be9e789d7459b3d4d', length: this.boxLength, face1Side: "top", face1Corner: "bottom-left", face2Side: "front", face2Corner: "top-left", face3Side: "left", face3Corner: "top-right", onPointerDown: this.handleStandardView(StandardView.TOP_FRONT_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: '607d1c0db03091fe6fe49ff8bb3f1d2e4e9ee737', length: this.boxLength, face1Side: "top", face1Corner: "bottom-right", face2Side: "front", face2Corner: "top-right", face3Side: "right", face3Corner: "top-left", onPointerDown: this.handleStandardView(StandardView.TOP_FRONT_LEFT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: 'bf417c48dc652d2692d6a122cd8aa4f9aae65331', length: this.boxLength, face1Side: "bottom", face1Corner: "top-right", face2Side: "front", face2Corner: "bottom-right", face3Side: "right", face3Corner: "bottom-left", onPointerDown: this.handleStandardView(StandardView.BOTTOM_FRONT_LEFT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: '59f7db859f9d06921e2fa3c30fa2527bc95ff3ce', length: this.boxLength, face1Side: "bottom", face1Corner: "top-left", face2Side: "front", face2Corner: "bottom-left", face3Side: "left", face3Corner: "bottom-right", onPointerDown: this.handleStandardView(StandardView.BOTTOM_FRONT_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: 'f8eb7ba2b8b9384c6fed7f1e930eb872599b7372', length: this.boxLength, face1Side: "top", face1Corner: "top-right", face2Side: "back", face2Corner: "top-left", face3Side: "right", face3Corner: "top-right", onPointerDown: this.handleStandardView(StandardView.TOP_BACK_LEFT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: '122f91a6146b62e145d0e710b8d1b7605b744073', length: this.boxLength, face1Side: "top", face1Corner: "top-left", face2Side: "back", face2Corner: "top-right", face3Side: "left", face3Corner: "top-left", onPointerDown: this.handleStandardView(StandardView.TOP_BACK_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: '4114134608fa6903bd0226a541d153175418102b', length: this.boxLength, face1Side: "bottom", face1Corner: "bottom-left", face2Side: "back", face2Corner: "bottom-right", face3Side: "left", face3Corner: "bottom-left", onPointerDown: this.handleStandardView(StandardView.BOTTOM_BACK_RIGHT), disabled: this.standardViewsOff }), h(ViewCubeCorner, { key: '1d4fd46fb9edf0821e3e611c863837d1e9bc7ec8', length: this.boxLength, face1Side: "bottom", face1Corner: "bottom-right", face2Side: "back", face2Corner: "bottom-left", face3Side: "right", face3Corner: "bottom-right", onPointerDown: this.handleStandardView(StandardView.BOTTOM_BACK_LEFT), disabled: this.standardViewsOff })))));
    }
    static get is() { return "vertex-viewer-view-cube"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["viewer-view-cube.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["viewer-view-cube.css"]
        };
    }
    static get properties() {
        return {
            "xPositiveLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the side of the cube on the positive x-axis."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "x-positive-label",
                "defaultValue": "'Right'"
            },
            "xNegativeLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the side of the cube on the negative x-axis."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "x-negative-label",
                "defaultValue": "'Left'"
            },
            "yPositiveLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the side of the cube on the positive y-axis."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "y-positive-label",
                "defaultValue": "'Top'"
            },
            "yNegativeLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the side of the cube on the negative y-axis."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "y-negative-label",
                "defaultValue": "'Bottom'"
            },
            "zPositiveLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the side of the cube on the positive z-axis."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "z-positive-label",
                "defaultValue": "'Front'"
            },
            "zNegativeLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the side of the cube on the negative z-axis."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "z-negative-label",
                "defaultValue": "'Back'"
            },
            "standardViewsOff": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Disables interactions for standard views."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "standard-views-off",
                "defaultValue": "false"
            },
            "viewAll": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Whether to perform a `viewAll` when clicking on the view cube. If this\nis set to `false`, the current `lookAt` point will be maintained, and the\ncamera's `position` and `up` vectors will be aligned to the standard view.\nDefaults to `true`.\n\n**Note** Setting this value to `false` can result in the camera being placed\nunderneath geometry depending on the current `viewVector` length, resulting\nin a view that may be unexpected."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "view-all",
                "defaultValue": "true"
            },
            "animationDuration": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The duration of the animation, in milliseconds, when a user performs a\nstandard view interaction. Set to 0 to disable animations."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "animation-duration",
                "defaultValue": "500"
            },
            "triadOff": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Disables the display of the triad."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "triad-off",
                "defaultValue": "false"
            },
            "worldOrientation": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Orientation",
                    "resolved": "Orientation",
                    "references": {
                        "Orientation": {
                            "location": "import",
                            "path": "../../lib/types",
                            "id": "src/lib/types/index.ts::Orientation",
                            "referenceLocation": "Orientation"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": undefined
                        }],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "Orientation.DEFAULT"
            },
            "camera": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "FramePerspectiveCamera",
                    "resolved": "FramePerspectiveCamera | undefined",
                    "references": {
                        "FramePerspectiveCamera": {
                            "location": "import",
                            "path": "../../lib/types",
                            "id": "src/lib/types/index.ts::FramePerspectiveCamera",
                            "referenceLocation": "FramePerspectiveCamera"
                        }
                    }
                },
                "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 element that is connected to the view cube."
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get states() {
        return {
            "boxLength": {},
            "triadPosition": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "viewer",
                "methodName": "handleViewerChanged"
            }];
    }
}
//# sourceMappingURL=viewer-view-cube.js.map
