/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Notification
 */
import "./StatusMessagesContainer.scss";
import * as React from "react";
import classnames from "classnames";
import { OutputMessageType } from "@itwin/core-frontend";
import { ToastMessage } from "./ToastMessage";
import { StickyMessage } from "./StickyMessage";
import { ActivityMessage } from "./ActivityMessage";
import { useLayoutResizeObserver } from "@itwin/core-react";
/** Component that renders one or more Toast, Sticky or Activity messages
 * @internal
 * @deprecated in 3.3. Replaced by Toaster from @itwin/itwinui-react.
 */
export function StatusMessagesContainer(props) {
    const [containerElement, setContainerElement] = React.useState(null);
    const isMountedRef = React.useRef(false);
    React.useEffect(() => {
        if (!isMountedRef.current && containerRef.current) {
            isMountedRef.current = true;
            setContainerElement(containerRef.current);
        }
    }, []);
    const messages = props.messages;
    const containerRef = React.useRef(null);
    const [, height] = useLayoutResizeObserver(containerElement);
    const [addScroll, setAddScroll] = React.useState(false);
    React.useLayoutEffect(() => {
        var _a, _b;
        // istanbul ignore else
        if (containerElement) {
            // istanbul ignore next
            const windowHeight = (_b = (_a = containerElement.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.innerHeight) !== null && _b !== void 0 ? _b : 800;
            const maxHeight = Math.floor(windowHeight * .66);
            setAddScroll((height !== null && height !== void 0 ? height : 0) >= maxHeight);
        }
    }, [height, containerElement]);
    if (!(props.activityMessageInfo && props.isActivityMessageVisible) && props.messages.length === 0)
        return null;
    return (React.createElement("div", { ref: containerRef, className: classnames("uifw-statusbar-messages-container", addScroll && "uifw-scrollable") },
        React.createElement("ul", { className: "uifw-statusbar-message-list" },
            messages.length > 0 &&
                messages.map((message) => {
                    let messageNode = null;
                    if (message.messageDetails.msgType === OutputMessageType.Toast) {
                        messageNode = (React.createElement("li", { key: message.id },
                            React.createElement(ToastMessage, { id: message.id, messageDetails: message.messageDetails, severity: message.severity, closeMessage: props.closeMessage, toastTarget: props.toastTarget })));
                    }
                    else if (message.messageDetails.msgType === OutputMessageType.Sticky) {
                        messageNode = (React.createElement("li", { key: message.id },
                            React.createElement(StickyMessage, { id: message.id, messageDetails: message.messageDetails, severity: message.severity, closeMessage: props.closeMessage })));
                    }
                    return messageNode;
                }),
            (props.activityMessageInfo !== undefined && props.isActivityMessageVisible) &&
                React.createElement("li", { key: "activity-message" },
                    React.createElement(ActivityMessage, { activityMessageInfo: props.activityMessageInfo, cancelActivityMessage: props.cancelActivityMessage, dismissActivityMessage: props.dismissActivityMessage })))));
}
//# sourceMappingURL=StatusMessagesContainer.js.map