/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Item
 */
import * as React from "react";
import { ConditionalBooleanValue } from "@itwin/appui-abstract";
import { ActionButtonItemDef } from "./ActionButtonItemDef";
/** An Item that renders a React component.
 * @public
 */
export class CustomItemDef extends ActionButtonItemDef {
    constructor(props) {
        super(props);
        if (props.customId)
            this.customId = props.customId;
        else {
            CustomItemDef._sId++;
            this.customId = CustomItemDef.customIdPrefix + CustomItemDef._sId;
        }
        this.reactElement = props.reactElement;
        this.popupPanelNode = props.popupPanelNode;
    }
    get id() {
        return this.customId;
    }
    toolbarReactNode(index) {
        if (!this.isVisible || ConditionalBooleanValue.getValue(this.isHidden)) // eslint-disable-line deprecation/deprecation
            return null;
        let clone;
        // istanbul ignore else
        if (this.reactElement && React.isValidElement(this.reactElement)) {
            const key = this.getKey(index);
            const cloneProps = {
                key,
                onSizeKnown: this.handleSizeKnown,
            };
            clone = React.cloneElement(this.reactElement, cloneProps);
        }
        return clone;
    }
}
CustomItemDef._sId = 0;
CustomItemDef.customIdPrefix = "Custom-";
//# sourceMappingURL=CustomItemDef.js.map