"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.CursorPrompt = void 0;
require("./CursorPrompt.scss");
const React = require("react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const core_react_1 = require("@itwin/core-react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const CursorInformation_1 = require("../CursorInformation");
const CursorPopupManager_1 = require("../cursorpopup/CursorPopupManager");
/** @internal */
class CursorPrompt {
    constructor(timeOut, fadeOut) {
        this._relativePosition = appui_abstract_1.RelativePosition.BottomRight;
        this._offset = new core_react_1.Point(20, 20);
        this._popupId = "cursor-prompt";
        this._startCursorPopup = (promptElement) => {
            CursorPopupManager_1.CursorPopupManager.open(this._popupId, promptElement, CursorInformation_1.CursorInformation.cursorPosition, this._offset, this._relativePosition, 0, { shadow: true });
            if (!CursorInformation_1.CursorInformation.onCursorUpdatedEvent.has(this._handleCursorUpdated))
                CursorInformation_1.CursorInformation.onCursorUpdatedEvent.addListener(this._handleCursorUpdated);
        };
        this._endCursorPopup = (fadeOut) => {
            CursorPopupManager_1.CursorPopupManager.close(this._popupId, false, fadeOut);
            CursorInformation_1.CursorInformation.onCursorUpdatedEvent.removeListener(this._handleCursorUpdated);
        };
        this._handleCursorUpdated = (args) => {
            CursorPopupManager_1.CursorPopupManager.updatePosition(args.newPt);
        };
        this._timeOut = timeOut;
        this._fadeOut = fadeOut;
        this._timer = new core_react_1.Timer(timeOut);
    }
    display(toolIconSpec, instruction, offset = { x: 20, y: 20 }, relativePosition = appui_abstract_1.RelativePosition.BottomRight) {
        if (!instruction.text) {
            // istanbul ignore else
            if (this._timer.isRunning)
                this.close(false);
            return;
        }
        this._relativePosition = relativePosition;
        this._offset = core_react_1.Point.create(offset);
        const promptElement = (React.createElement("div", { className: "uifw-cursor-prompt" },
            toolIconSpec && (React.createElement("span", { className: "uifw-cursor-prompt-icon" },
                React.createElement(core_react_1.Icon, { iconSpec: toolIconSpec }))),
            React.createElement(itwinui_react_1.Text, { variant: "body", className: "uifw-cursor-prompt-text" }, instruction.text)));
        this._startCursorPopup(promptElement);
        this._timer.setOnExecute(() => this._endCursorPopup(this._fadeOut));
        this._timer.delay = this._timeOut;
        this._timer.start();
    }
    /** @internal - unit testing */
    close(fadeOut) {
        this._timer.stop();
        this._endCursorPopup(fadeOut);
    }
}
exports.CursorPrompt = CursorPrompt;
//# sourceMappingURL=CursorPrompt.js.map