/*---------------------------------------------------------------------------------------------
* 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
 */
import "./ToolSettingsContent.scss";
import classnames from "classnames";
import * as React from "react";
import { ResizableContainerObserver } from "@itwin/core-react";
import { ToolSettingsWidgetMode, WidgetContent } from "@itwin/appui-layout-react";
/**  @internal */
export 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 = classnames("uifw-tool-settings-content", this.props.mode === ToolSettingsWidgetMode.TitleBar && "uifw-title-bar", this.props.mode === ToolSettingsWidgetMode.Tab && "uifw-tab");
        return (React.createElement(WidgetContent // eslint-disable-line deprecation/deprecation
        , { anchor: this.props.anchor, className: className, containerRef: this._container, content: React.createElement(ToolSettingsContentContext.Provider, { value: {
                    availableContentWidth: this.state.availableContentWidth,
                } },
                this.props.children,
                React.createElement("div", { className: "uifw-zone-measurer" },
                    React.createElement(ResizableContainerObserver, { onResize: this._handleResize })),
                React.createElement("div", { className: "uifw-measurer", ref: this._measurer }),
                React.createElement("div", { className: "uifw-expander" })) }));
    }
}
/** @internal */
export const ToolSettingsContentContext = React.createContext({
    availableContentWidth: 0,
});
//# sourceMappingURL=ToolSettingsContent.js.map