"use strict";
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Widget
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackstageAppButton = void 0;
const React = require("react");
const core_bentley_1 = require("@itwin/core-bentley");
const core_react_1 = require("@itwin/core-react");
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
const UiFramework_1 = require("../UiFramework");
const App_1 = require("../layout/widget/tools/button/App");
const useTranslation_1 = require("../hooks/useTranslation");
/** Component shown in the top-left corner of the content manipulation area. It is usually used to toggle the display of a backstage or navigate between frontstages.
 * @public
 */
function BackstageAppButton({ 
// eslint-disable-next-line deprecation/deprecation
icon, iconNode, label, execute, }) {
    const { translate } = (0, useTranslation_1.useTranslation)();
    label = label ?? translate("commands.openBackstage");
    const isInitialMount = React.useRef(true);
    const { onElementRef, proximityScale } = (0, core_react_1.useWidgetOpacityContext)();
    const ref = React.useRef(null);
    const handleClick = React.useCallback(() => {
        if (execute) {
            execute();
            return;
        }
        UiFramework_1.UiFramework.backstage.toggle();
    }, [execute]);
    React.useEffect(() => {
        if (isInitialMount.current) {
            isInitialMount.current = false;
            onElementRef(ref);
        }
    }, [onElementRef]);
    let buttonProximityScale;
    if ((UiFramework_1.UiFramework.visibility.useProximityOpacity || // eslint-disable-line deprecation/deprecation
        UiFramework_1.UiFramework.visibility.snapWidgetOpacity) &&
        !core_bentley_1.ProcessDetector.isMobileBrowser) {
        buttonProximityScale = proximityScale;
    }
    // eslint-disable-next-line deprecation/deprecation
    const specIcon = icon ? React.createElement(core_react_1.Icon, { iconSpec: icon }) : undefined;
    return (React.createElement("div", { ref: ref, className: "uifw-app-button-small" },
        React.createElement(App_1.AppButton, { small: true, mouseProximity: buttonProximityScale, onClick: handleClick, icon: iconNode ?? specIcon ?? React.createElement(itwinui_icons_react_1.SvgHome, null), title: label })));
}
exports.BackstageAppButton = BackstageAppButton;
//# sourceMappingURL=BackstageAppButton.js.map