/*---------------------------------------------------------------------------------------------
 * 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 "./CursorPrompt.scss";
import * as React from "react";
import { RelativePosition } from "@itwin/appui-abstract";
import { Icon, Point, Timer } from "@itwin/core-react";
import { Text } from "@itwin/itwinui-react";
import { CursorInformation } from "../CursorInformation";
import { CursorPopupManager } from "../cursorpopup/CursorPopupManager";
/** @internal */
export class CursorPrompt {
    constructor(timeOut, fadeOut) {
        this._relativePosition = RelativePosition.BottomRight;
        this._offset = new Point(20, 20);
        this._popupId = "cursor-prompt";
        this._startCursorPopup = (promptElement) => {
            CursorPopupManager.open(this._popupId, promptElement, CursorInformation.cursorPosition, this._offset, this._relativePosition, 0, { shadow: true });
            if (!CursorInformation.onCursorUpdatedEvent.has(this._handleCursorUpdated))
                CursorInformation.onCursorUpdatedEvent.addListener(this._handleCursorUpdated);
        };
        this._endCursorPopup = (fadeOut) => {
            CursorPopupManager.close(this._popupId, false, fadeOut);
            CursorInformation.onCursorUpdatedEvent.removeListener(this._handleCursorUpdated);
        };
        this._handleCursorUpdated = (args) => {
            CursorPopupManager.updatePosition(args.newPt);
        };
        this._timeOut = timeOut;
        this._fadeOut = fadeOut;
        // eslint-disable-next-line deprecation/deprecation
        this._timer = new Timer(timeOut);
    }
    display(toolIconSpec, instruction, offset = { x: 20, y: 20 }, relativePosition = RelativePosition.BottomRight) {
        if (!instruction.text) {
            if (this._timer.isRunning)
                this.close(false);
            return;
        }
        this._relativePosition = relativePosition;
        this._offset = Point.create(offset);
        const promptElement = (React.createElement("div", { className: "uifw-cursor-prompt" },
            toolIconSpec && (React.createElement("span", { className: "uifw-cursor-prompt-icon" },
                React.createElement(Icon, { iconSpec: toolIconSpec }))),
            React.createElement(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);
    }
}
//# sourceMappingURL=CursorPrompt.js.map