
import { alert } from '../../../../base/browser/ui/aria/aria.js';
import { localize } from '../../../../nls.js';
import { NotificationChangeType, NotificationViewItemContentChangeKind } from '../../../common/notifications.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { toErrorMessage } from '../../../../base/common/errorMessage.js';
import { NotificationPriority } from '../../../../platform/notification/common/notification.js';
import { Event } from '../../../../base/common/event.js';
import Severity$1 from '../../../../base/common/severity.js';

class NotificationsAlerts extends Disposable {
    constructor(model) {
        super();
        this.model = model;
        for (const notification of model.notifications) {
            this.triggerAriaAlert(notification);
        }
        this.registerListeners();
    }
    registerListeners() {
        this._register(this.model.onDidChangeNotification(e => this.onDidChangeNotification(e)));
    }
    onDidChangeNotification(e) {
        if (e.kind === NotificationChangeType.ADD) {
            this.triggerAriaAlert(e.item);
            if (e.item.severity === Severity$1.Error) {
                if (e.item.message.original instanceof Error) {
                    console.error(e.item.message.original);
                } else {
                    console.error(toErrorMessage(( e.item.message.linkedText.toString()), true));
                }
            }
        }
    }
    triggerAriaAlert(notification) {
        if (notification.priority === NotificationPriority.SILENT) {
            return;
        }
        const listener = notification.onDidChangeContent(e => {
            if (e.kind === NotificationViewItemContentChangeKind.MESSAGE) {
                this.doTriggerAriaAlert(notification);
            }
        });
        Event.once(notification.onDidClose)(() => listener.dispose());
        this.doTriggerAriaAlert(notification);
    }
    doTriggerAriaAlert(notification) {
        let alertText;
        if (notification.severity === Severity$1.Error) {
            alertText = ( localize(3744, "Error: {0}", (notification.message.linkedText.toString())));
        } else if (notification.severity === Severity$1.Warning) {
            alertText = ( localize(3745, "Warning: {0}", (notification.message.linkedText.toString())));
        } else {
            alertText = ( localize(3746, "Info: {0}", (notification.message.linkedText.toString())));
        }
        alert(alertText);
    }
}

export { NotificationsAlerts };
