"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.AppNotificationManager = void 0;
const core_frontend_1 = require("@itwin/core-frontend");
const ElementTooltip_1 = require("../feedback/ElementTooltip");
const UiFramework_1 = require("../UiFramework");
const MessageManager_1 = require("./MessageManager");
const Pointer_1 = require("./Pointer");
/**
 * The AppNotificationManager class is a subclass of NotificationManager in @itwin/core-frontend.
 * This implementation uses the iTwin.js UI library to display alerts, messages, prompts and tooltips.
 * @public
 */
class AppNotificationManager extends core_frontend_1.NotificationManager {
    /** Output a prompt, given an i18n key.
     */
    outputPromptByKey(key) {
        this.outputPrompt(UiFramework_1.UiFramework.localization.getLocalizedString(key));
    }
    /** Output a prompt to the user. A 'prompt' indicates an action the user should take to proceed.
     */
    outputPrompt(prompt) {
        MessageManager_1.MessageManager.outputPrompt(prompt);
        const mainInstruction = core_frontend_1.ToolAssistance.createInstruction("", prompt);
        const instructions = core_frontend_1.ToolAssistance.createInstructions(mainInstruction);
        MessageManager_1.MessageManager.setToolAssistance(instructions);
    }
    /** Output a message and/or alert to the user. */
    outputMessage(message) {
        MessageManager_1.MessageManager.outputMessage(message);
    }
    /** Output a MessageBox and wait for response from the user.
     * @param mbType       The MessageBox type.
     * @param message      The message to display.
     * @param icon         The MessageBox icon type.
     * @return the response from the user.
     */
    async openMessageBox(mbType, message, icon) {
        return MessageManager_1.MessageManager.openMessageBox(mbType, message, icon);
    }
    /**
     * Set up for activity messages.
     * @param details  The activity message details.
     * @return true if the message was displayed, false if an invalid priority is specified.
     */
    setupActivityMessage(details) {
        return MessageManager_1.MessageManager.setupActivityMessageDetails(details);
    }
    /**
     * Output an activity message to the user.
     * @param messageText      The message text.
     * @param percentComplete  The percentage of completion.
     * @return true if the message was displayed, false if the message could not be displayed.
     */
    outputActivityMessage(messageText, percentComplete) {
        return MessageManager_1.MessageManager.setupActivityMessageValues(messageText, percentComplete);
    }
    /**
     * End an activity message.
     * @param reason       Reason for the end of the Activity Message.
     * @return true if the message was ended successfully, false if the activityMessage could not be ended.
     */
    endActivityMessage(reason) {
        let result = false;
        switch (reason) {
            case core_frontend_1.ActivityMessageEndReason.Completed:
                result = MessageManager_1.MessageManager.endActivityMessage(true);
                break;
            case core_frontend_1.ActivityMessageEndReason.Cancelled:
                result = MessageManager_1.MessageManager.endActivityMessage(false);
                break;
        }
        return result;
    }
    /** Update message position created with [[OutputMessageType.Pointer]].
     * @param displayPoint        Point at which to display the Pointer type message.
     * @param relativePosition    Position relative to displayPoint at which to display the Pointer type message.
     */
    updatePointerMessage(displayPoint, relativePosition) {
        Pointer_1.PointerMessage.updateMessage(displayPoint, relativePosition);
    }
    /** Hides the Pointer message. */
    closePointerMessage() {
        Pointer_1.PointerMessage.hideMessage();
    }
    /** Return true if _showTooltip has an implementation and will display a tooltip. */
    get isToolTipSupported() { return true; }
    /** Return true if the tooltip is currently open. */
    get isToolTipOpen() { return ElementTooltip_1.ElementTooltip.isTooltipVisible; }
    /** Clear the ToolTip if it is currently open. If not open, does nothing. */
    clearToolTip() {
        // istanbul ignore else
        if (this.isToolTipOpen)
            ElementTooltip_1.ElementTooltip.hideTooltip();
    }
    /** Show a ToolTip window.
     * @param el       The HTMLElement that anchors the toolTip.
     * @param message  The message to display inside the ToolTip
     * @param pt       An optional location, relative to the origin of el, for the ToolTip. If undefined, center of el.
     * @param options  Options that supply additional information about how the ToolTip should function.
     */
    _showToolTip(el, message, pt, options) {
        ElementTooltip_1.ElementTooltip.showTooltip(el, message, pt, options);
    }
    /** Hide a InputField message. */
    closeInputFieldMessage() {
        MessageManager_1.MessageManager.hideInputFieldMessage();
    }
    /** Setup tool assistance instructions for a tool. The instructions include the main instruction, which includes the current prompt.
     * @param instructions The tool assistance instructions.
     * @public
     */
    setToolAssistance(instructions) {
        MessageManager_1.MessageManager.outputPrompt(instructions ? instructions.mainInstruction.text : /* istanbul ignore next */ "");
        MessageManager_1.MessageManager.setToolAssistance(instructions);
    }
}
exports.AppNotificationManager = AppNotificationManager;
//# sourceMappingURL=AppNotificationManager.js.map