/*---------------------------------------------------------------------------------------------
 * 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 svgCubeFacesBottom from "@bentley/icons-generic/icons/cube-faces/bottom.svg";
import svgCubeFacesFront from "@bentley/icons-generic/icons/cube-faces/front.svg";
import svgCubeFacesIsoLeft from "@bentley/icons-generic/icons/cube-faces/iso-left.svg";
import svgCubeFacesIsoRight from "@bentley/icons-generic/icons/cube-faces/iso-right.svg";
import svgCubeFacesLeft from "@bentley/icons-generic/icons/cube-faces/left.svg";
import svgCubeFacesRear from "@bentley/icons-generic/icons/cube-faces/rear.svg";
import svgCubeFacesRight from "@bentley/icons-generic/icons/cube-faces/right.svg";
import svgCubeFacesTop from "@bentley/icons-generic/icons/cube-faces/top.svg";
import { RelativePosition, ToolbarItemUtilities } from "@itwin/appui-abstract";
import { Columns, GroupColumn, GroupTool, Panel, } from "@itwin/components-react";
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";
import { ExpandableButton as NZ_Expandable } from "../layout/widget/tools/button/Expandable";
import { ToolbarIcon as NZ_Icon } from "../layout/widget/tools/button/Icon";
import { NavigationAidControl } from "./NavigationAidControl";
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 deprecation/deprecation
export class StandardRotationNavigationAidControl extends NavigationAidControl {
    // eslint-disable-next-line deprecation/deprecation
    constructor(info, options) {
        super(info, options);
        this.reactNode = React.createElement(StandardRotationNavigationAid, null);
    }
}
StandardRotationNavigationAidControl.navigationAidId = "StandardRotationNavigationAid";
/** A 3D Standard Rotation Navigation Aid.
 * @public
 */
export class StandardRotationNavigationAid extends React.Component {
    constructor(props) {
        super(props);
        this._handleRef = (element) => {
            this.setState(() => ({ element }));
        };
        this._handlePopupClose = () => {
            this.setState(() => ({ isExpanded: false }));
        };
        this._toggleIsExpanded = () => {
            this.setState((prevState) => ({ isExpanded: !prevState.isExpanded }));
        };
        this._handleListItemClicked = (item) => {
            const selected = item;
            this.setState(() => ({ isExpanded: false, selected }), () => ViewportComponentEvents.setStandardRotation(selected));
        };
        const list = [
            {
                label: UiFramework.translate("rotations.top"),
                iconsSpec: svgCubeFacesTop,
            },
            {
                label: UiFramework.translate("rotations.bottom"),
                iconsSpec: svgCubeFacesBottom,
            },
            {
                label: UiFramework.translate("rotations.left"),
                iconsSpec: svgCubeFacesLeft,
            },
            {
                label: UiFramework.translate("rotations.right"),
                iconsSpec: svgCubeFacesRight,
            },
            {
                label: UiFramework.translate("rotations.front"),
                iconsSpec: svgCubeFacesFront,
            },
            {
                label: UiFramework.translate("rotations.rear"),
                iconsSpec: svgCubeFacesRear,
            },
            {
                label: UiFramework.translate("rotations.isoLeft"),
                iconsSpec: svgCubeFacesIsoLeft,
            },
            {
                label: UiFramework.translate("rotations.isoRight"),
                iconsSpec: svgCubeFacesIsoRight,
            },
        ];
        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())));
    }
    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 deprecation/deprecation
                        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