/*---------------------------------------------------------------------------------------------
* 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 * as _ from "lodash";
import * as React from "react";
/**
 * A component that expects its children to be a function that will be passed the current component Props.
 * @public
 * @deprecated in 3.3. In upcoming version, all props passed down to the bool function will be undefined, making this component useless.
 */
export class ConditionalField extends React.PureComponent {
    constructor(props) {
        super(props);
        this._resolveBooleanValue = () => {
            var _a;
            // eslint-disable-next-line deprecation/deprecation
            const boolValue = this.props.boolFunc({ ...this.props, isInFooterMode: (_a = this.props.isInFooterMode) !== null && _a !== void 0 ? _a : true });
            if (this.state.boolValue !== boolValue) {
                this.setState({ boolValue });
            }
        };
        this._hasNoChildren = (children) => React.Children.count(children) === 0;
        this.state = {
            boolValue: undefined !== props.defaultValue ? props.defaultValue : true,
        };
    }
    componentDidMount() {
        this._resolveBooleanValue();
    }
    componentDidUpdate(prevProps) {
        if (!_.isEqual(prevProps, this.props))
            this._resolveBooleanValue();
    }
    render() {
        const { 
        // do not bleed our props
        children, eventIds, boolFunc, defaultValue, // eslint-disable-line @typescript-eslint/no-unused-vars
        // eslint-disable-next-line comma-dangle
        ...otherProps // pass-through props
         } = this.props;
        const boolValue = this.state.boolValue;
        return (typeof children === "function" ?
            children(boolValue, otherProps)
            : !this._hasNoChildren(children)
                ? React.Children.only(children)
                : null);
    }
}
//# sourceMappingURL=ConditionalField.js.map