/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module StatusBar
 */
import "./Indicator.scss";
import classnames from "classnames";
import * as React from "react";
import { ConditionalStringValue, StatusBarLabelSide } from "@itwin/appui-abstract";
import { Icon } from "@itwin/core-react";
import { FooterPopup } from "@itwin/appui-layout-react";
/** General-purpose [[Footer]] indicator. Shows an icon and supports an optional popup dialog.
 * @deprecated in 3.6. Use [[StatusBarIndicator]] or [[StatusBarLabelIndicator]] instead.
 * @beta
 */
export function Indicator(props) {
    // eslint-disable-next-line deprecation/deprecation
    const { className, contentType, dialog, iconName, iconSpec, isInFooterMode, isLabelVisible, label, labelSide, onClick, opened, style, toolTip } = props;
    const hasClickAction = React.useMemo(() => !!onClick || !!dialog, [dialog, onClick]);
    const [isOpen, setIsOpen] = React.useState(!!opened);
    const handleOnIndicatorClick = React.useCallback(() => {
        if (dialog) {
            setIsOpen(!isOpen);
        }
        onClick && onClick();
    }, [dialog, isOpen, onClick]);
    const inFooter = React.useMemo(() => false === isInFooterMode ? false : true, [isInFooterMode]);
    const target = React.useRef(null);
    const icon = React.useMemo(() => iconSpec !== null && iconSpec !== void 0 ? iconSpec : iconName, [iconSpec, iconName]);
    const title = React.useMemo(() => toolTip !== null && toolTip !== void 0 ? toolTip : label, [toolTip, label]);
    const classNames = classnames("uifw-footer-label-left", "uifw-footer-indicator", inFooter && "nz-footer-mode", hasClickAction && "uifw-footer-action", labelSide === StatusBarLabelSide.Right && "uifw-footer-label-reversed", // eslint-disable-line deprecation/deprecation
    className);
    return (React.createElement(React.Fragment, null,
        React.createElement("div", { ref: target, role: "button", tabIndex: -1, className: classNames, title: title, style: style, onClick: handleOnIndicatorClick },
            isLabelVisible && label && React.createElement("span", { className: "nz-label" }, ConditionalStringValue.getValue(label)),
            icon && React.createElement("div", { className: "uifw-indicator-icon" },
                React.createElement(Icon, { iconSpec: icon }))),
        dialog && React.createElement(FooterPopup, { contentType: contentType, target: target.current, onClose: () => setIsOpen(false), isOpen: isOpen }, dialog)));
}
//# sourceMappingURL=Indicator.js.map