"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 Notification
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusMessagesContainer = void 0;
require("./StatusMessagesContainer.scss");
const React = require("react");
const classnames_1 = require("classnames");
const core_frontend_1 = require("@itwin/core-frontend");
const ToastMessage_1 = require("./ToastMessage");
const StickyMessage_1 = require("./StickyMessage");
const ActivityMessage_1 = require("./ActivityMessage");
const core_react_1 = require("@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.
 */
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] = (0, core_react_1.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: (0, classnames_1.default)("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 === core_frontend_1.OutputMessageType.Toast) {
                        messageNode = (React.createElement("li", { key: message.id },
                            React.createElement(ToastMessage_1.ToastMessage, { id: message.id, messageDetails: message.messageDetails, severity: message.severity, closeMessage: props.closeMessage, toastTarget: props.toastTarget })));
                    }
                    else if (message.messageDetails.msgType === core_frontend_1.OutputMessageType.Sticky) {
                        messageNode = (React.createElement("li", { key: message.id },
                            React.createElement(StickyMessage_1.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_1.ActivityMessage, { activityMessageInfo: props.activityMessageInfo, cancelActivityMessage: props.cancelActivityMessage, dismissActivityMessage: props.dismissActivityMessage })))));
}
exports.StatusMessagesContainer = StatusMessagesContainer;
//# sourceMappingURL=StatusMessagesContainer.js.map