/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module NavigationAids
 */
import { SvgCubeFaceBottom } from "../icons/cube-faces/SvgCubeFaceBottom.js";
import { SvgCubeFaceFront } from "../icons/cube-faces/SvgCubeFaceFront.js";
import { SvgCubeFaceIsoLeft } from "../icons/cube-faces/SvgCubeFaceIsoLeft.js";
import { SvgCubeFaceIsoRight } from "../icons/cube-faces/SvgCubeFaceIsoRight.js";
import { SvgCubeFaceLeft } from "../icons/cube-faces/SvgCubeFaceLeft.js";
import { SvgCubeFaceRear } from "../icons/cube-faces/SvgCubeFaceRear.js";
import { SvgCubeFaceRight } from "../icons/cube-faces/SvgCubeFaceRight.js";
import { SvgCubeFaceTop } from "../icons/cube-faces/SvgCubeFaceTop.js";
import { RelativePosition, ToolbarItemUtilities } from "@itwin/appui-abstract";
import { Columns, GroupColumn, GroupTool, Panel, } from "@itwin/components-react/internal";
import { StandardViewId } from "@itwin/core-frontend";
import { Icon, Popup } from "@itwin/core-react";
import { ViewportComponentEvents } from "@itwin/imodel-components-react";
import classnames from "classnames";
import * as React from "react";
import { UiFramework } from "../UiFramework.js";
import { ExpandableButton as NZ_Expandable } from "../layout/widget/tools/button/Expandable.js";
import { ToolbarIcon as NZ_Icon } from "../layout/widget/tools/button/Icon.js";
import { NavigationAidControl } from "./NavigationAidControl.js";
import "./StandardRotationNavigationAid.scss";
/** A 3D Standard Rotation Navigation Aid control.
 * @public
 * @deprecated in 4.16.0. Use {@link StandardRotationNavigationAid} component instead.
 */
// eslint-disable-next-line @typescript-eslint/no-deprecated
export class StandardRotationNavigationAidControl extends NavigationAidControl {
    static navigationAidId = "StandardRotationNavigationAid";
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    constructor(info, options) {
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        super(info, options);
        this.reactNode = React.createElement(StandardRotationNavigationAid, null);
    }
}
/** A 3D Standard Rotation Navigation Aid.
 * @public
 */
export class StandardRotationNavigationAid extends React.Component {
    state;
    constructor(props) {
        super(props);
        const list = [
            {
                label: UiFramework.translate("rotations.top"),
                iconsSpec: React.createElement(SvgCubeFaceTop, null),
            },
            {
                label: UiFramework.translate("rotations.bottom"),
                iconsSpec: React.createElement(SvgCubeFaceBottom, null),
            },
            {
                label: UiFramework.translate("rotations.left"),
                iconsSpec: React.createElement(SvgCubeFaceLeft, null),
            },
            {
                label: UiFramework.translate("rotations.right"),
                iconsSpec: React.createElement(SvgCubeFaceRight, null),
            },
            {
                label: UiFramework.translate("rotations.front"),
                iconsSpec: React.createElement(SvgCubeFaceFront, null),
            },
            {
                label: UiFramework.translate("rotations.rear"),
                iconsSpec: React.createElement(SvgCubeFaceRear, null),
            },
            {
                label: UiFramework.translate("rotations.isoLeft"),
                iconsSpec: React.createElement(SvgCubeFaceIsoLeft, null),
            },
            {
                label: UiFramework.translate("rotations.isoRight"),
                iconsSpec: React.createElement(SvgCubeFaceIsoRight, null),
            },
        ];
        this.state = {
            element: null,
            isExpanded: false,
            list,
            selected: StandardViewId.Top,
        };
    }
    render() {
        const className = classnames("uifw-standard-rotation-navigation", this.props.className);
        return (React.createElement("div", { className: className, style: this.props.style, ref: this._handleRef },
            React.createElement(NZ_Expandable, { className: "expandable" },
                React.createElement(NZ_Icon, { className: "icon-button", icon: React.createElement("span", { className: classnames("three-d-icon", "icon") },
                        React.createElement(Icon, { iconSpec: this.state.list[this.state.selected].iconsSpec })), onClick: this._toggleIsExpanded, title: UiFramework.translate("standardRotationNavigationAid.title") })),
            React.createElement(Popup, { isOpen: this.state.isExpanded, offset: 0, onClose: this._handlePopupClose, position: RelativePosition.Bottom, target: this.state.element }, this.getExpandedContent())));
    }
    _handleRef = (element) => {
        this.setState(() => ({ element }));
    };
    _handlePopupClose = () => {
        this.setState(() => ({ isExpanded: false }));
    };
    _toggleIsExpanded = () => {
        this.setState((prevState) => ({ isExpanded: !prevState.isExpanded }));
    };
    _handleListItemClicked = (item) => {
        const selected = item;
        this.setState(() => ({ isExpanded: false, selected }), () => ViewportComponentEvents.setStandardRotation(selected));
    };
    getExpandedContent() {
        if (!this.state.isExpanded)
            return undefined;
        return (React.createElement(Panel, null,
            React.createElement(Columns, null,
                React.createElement(GroupColumn, null, this.state.list.map((item, itemIndex) => {
                    return (React.createElement(GroupTool, { key: itemIndex.toString(), label: item.label, 
                        // eslint-disable-next-line @typescript-eslint/no-deprecated
                        icon: React.createElement(Icon, { iconSpec: item.iconsSpec }), isActive: this.state.selected.valueOf() === itemIndex, onClick: () => this._handleListItemClicked(itemIndex), item: ToolbarItemUtilities.createActionButton("", 0, "", "", () => { }) }));
                })))));
    }
}
//# sourceMappingURL=StandardRotationNavigationAid.js.map