"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 Toolbar
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLabelProps = exports.useExpandsTo = exports.Item = void 0;
const React = require("react");
const core_bentley_1 = require("@itwin/core-bentley");
const core_react_1 = require("@itwin/core-react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const useConditionalProp_1 = require("../../hooks/useConditionalProp");
const Badge_1 = require("./Badge");
const Toolbar_1 = require("./Toolbar");
/** @internal */
exports.Item = React.forwardRef(function Item(props, ref) {
    const { item, ...other } = props;
    const label = (0, useConditionalProp_1.useConditionalProp)(item.label);
    const isDisabled = (0, useConditionalProp_1.useConditionalProp)(item.isDisabled);
    const isHidden = (0, useConditionalProp_1.useConditionalProp)(item.isHidden);
    // eslint-disable-next-line deprecation/deprecation
    const iconSpec = (0, useConditionalProp_1.useConditionalProp)(item.icon);
    const labelProps = useLabelProps();
    if (isHidden)
        return null;
    return (React.createElement(itwinui_react_1.IconButton, { className: props.className, styleType: "borderless", disabled: isDisabled, isActive: item.isActive, label: label, labelProps: labelProps, style: props.style, ref: ref, ...other },
        item.iconNode ?? React.createElement(core_react_1.Icon, { iconSpec: iconSpec }),
        React.createElement(Badge_1.Badge, { badge: item.badge, badgeKind: item.badgeKind }),
        props.children));
});
/** @internal */
function useExpandsTo() {
    const context = React.useContext(Toolbar_1.ToolbarContext);
    (0, core_bentley_1.assert)(!!context);
    const { expandsTo } = context;
    return expandsTo;
}
exports.useExpandsTo = useExpandsTo;
/** @internal */
function useLabelProps() {
    const context = React.useContext(Toolbar_1.ToolbarContext);
    const [internalVisible, setInternalVisible] = React.useState(false);
    const visible = context?.popoverOpen ? false : internalVisible;
    const placement = useExpandsTo();
    return {
        placement,
        visible,
        onVisibleChange: setInternalVisible,
    };
}
exports.useLabelProps = useLabelProps;
//# sourceMappingURL=Item.js.map