"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.ToolSettingsContentContext = exports.ToolSettingsContent = void 0;
require("./ToolSettingsContent.scss");
const classnames_1 = require("classnames");
const React = require("react");
const core_react_1 = require("@itwin/core-react");
const appui_layout_react_1 = require("@itwin/appui-layout-react");
/**  @internal */
class ToolSettingsContent extends React.PureComponent {
    constructor() {
        super(...arguments);
        this._container = React.createRef();
        this._measurer = React.createRef();
        this.state = {
            availableContentWidth: 0,
        };
        this._handleResize = () => {
            const container = this._container.current;
            const measurer = this._measurer.current;
            // istanbul ignore next
            if (!container || !measurer)
                return;
            container.classList.add("uifw-measure");
            const measurerBounds = measurer.getBoundingClientRect();
            container.classList.remove("uifw-measure");
            this.setState({ availableContentWidth: measurerBounds.width });
        };
    }
    render() {
        const className = (0, classnames_1.default)("uifw-tool-settings-content", this.props.mode === appui_layout_react_1.ToolSettingsWidgetMode.TitleBar && "uifw-title-bar", this.props.mode === appui_layout_react_1.ToolSettingsWidgetMode.Tab && "uifw-tab");
        return (React.createElement(appui_layout_react_1.WidgetContent // eslint-disable-line deprecation/deprecation
        , { anchor: this.props.anchor, className: className, containerRef: this._container, content: React.createElement(exports.ToolSettingsContentContext.Provider, { value: {
                    availableContentWidth: this.state.availableContentWidth,
                } },
                this.props.children,
                React.createElement("div", { className: "uifw-zone-measurer" },
                    React.createElement(core_react_1.ResizableContainerObserver, { onResize: this._handleResize })),
                React.createElement("div", { className: "uifw-measurer", ref: this._measurer }),
                React.createElement("div", { className: "uifw-expander" })) }));
    }
}
exports.ToolSettingsContent = ToolSettingsContent;
/** @internal */
exports.ToolSettingsContentContext = React.createContext({
    availableContentWidth: 0,
});
//# sourceMappingURL=ToolSettingsContent.js.map