/*---------------------------------------------------------------------------------------------
 * 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 { MessageManager } from "./MessageManager.js";
import { OutputMessageType } from "@itwin/core-frontend";
/** Manager for Status messages
 * @internal
 */
export class StatusMessageManager {
    _messages = [];
    _messageId = 0;
    initialize() {
        this._messages = [];
        this._messageId = 0;
    }
    get messages() {
        return this._messages;
    }
    add(messageDetails) {
        const id = this._messageId.toString();
        const severity = MessageManager.getSeverity(messageDetails);
        const messages = this._messages.slice();
        messages.splice(0, 0, { id, messageDetails, severity }); // Insert at beginning
        this._messages = messages;
        this._messageId++;
        /** Remove Sticky messages beyond the max displayed */
        const stickyMessages = this._messages.filter((message) => message.messageDetails.msgType === OutputMessageType.Sticky);
        if (stickyMessages.length > MessageManager.maxDisplayedStickyMessages) {
            const removeMessages = stickyMessages.slice(MessageManager.maxDisplayedStickyMessages);
            for (const removeMessage of removeMessages) {
                this.remove(removeMessage.id);
            }
        }
    }
    remove(id) {
        let result = false;
        const foundIndex = this._messages.findIndex((message) => message.id === id);
        if (foundIndex >= 0) {
            const messages = this._messages.slice();
            messages.splice(foundIndex, 1);
            this._messages = messages;
            result = true;
        }
        return result;
    }
}
//# sourceMappingURL=StatusMessageManager.js.map