"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.InputFieldMessage = void 0;
require("./InputField.scss");
const React = require("react");
const core_frontend_1 = require("@itwin/core-frontend");
const appui_abstract_1 = require("@itwin/appui-abstract");
const core_react_1 = require("@itwin/core-react");
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const MessageManager_1 = require("../messages/MessageManager");
/** InputField message pops up near pointer when attempting an invalid interaction.
 * @public
 * @deprecated in 4.16.0. Component is used internally. Use {@link MessageManager.displayInputFieldMessage} instead to open the message.
 */
class InputFieldMessage extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {
            message: "",
            isVisible: false,
            priority: core_frontend_1.OutputMessagePriority.None,
            showCloseButton: !!this.props.showCloseButton,
        };
        this._onInputMessageClose = () => {
            this.setState({ isVisible: false });
        };
        this._handleInputFieldMessageAddedEvent = (args) => {
            this.setState({
                inputFieldElement: args.target,
                message: args.messageText,
                isVisible: true,
                priority: args.priority,
                detailedMessage: args.detailedMessage,
            });
        };
        this._handleInputFieldMessageRemovedEvent = () => {
            this.setState({ isVisible: false });
        };
    }
    render() {
        const { isVisible, inputFieldElement, message, priority, detailedMessage, showCloseButton, } = this.state;
        if (!inputFieldElement || !message) {
            return null;
        }
        return (
        // eslint-disable-next-line deprecation/deprecation
        React.createElement(core_react_1.Popup, { isOpen: isVisible, position: appui_abstract_1.RelativePosition.BottomLeft, onClose: this._onInputMessageClose, target: inputFieldElement },
            React.createElement("div", { className: "uifw-popup-message-inputField" },
                React.createElement("div", { className: "uifw-popup-message-inputField-content" },
                    React.createElement("div", { className: "uifw-popup-message-inputField-primary" },
                        React.createElement(FieldIcon, { priority: priority }),
                        React.createElement("span", { className: "uifw-popup-message-text" },
                            React.createElement(core_react_1.MessageRenderer, { className: "uifw-popup-message-brief", message: message }),
                            detailedMessage && (
                            // eslint-disable-next-line deprecation/deprecation
                            React.createElement(core_react_1.MessageRenderer, { className: "uifw-popup-message-detailed", message: detailedMessage }))))),
                showCloseButton && (
                // eslint-disable-next-line jsx-a11y/click-events-have-key-events
                React.createElement("div", { className: "uifw-popup-message-close", onClick: this._onInputMessageClose, role: "button", tabIndex: -1 },
                    React.createElement(core_react_1.Icon, { iconSpec: React.createElement(itwinui_icons_react_1.SvgClose, null) }))))));
    }
    componentDidMount() {
        MessageManager_1.MessageManager.onInputFieldMessageAddedEvent.addListener(this._handleInputFieldMessageAddedEvent);
        MessageManager_1.MessageManager.onInputFieldMessageRemovedEvent.addListener(this._handleInputFieldMessageRemovedEvent);
    }
    componentWillUnmount() {
        MessageManager_1.MessageManager.onInputFieldMessageAddedEvent.removeListener(this._handleInputFieldMessageAddedEvent);
        MessageManager_1.MessageManager.onInputFieldMessageRemovedEvent.removeListener(this._handleInputFieldMessageRemovedEvent);
    }
}
exports.InputFieldMessage = InputFieldMessage;
function FieldIcon({ priority }) {
    let svg = React.createElement(itwinui_icons_react_1.SvgInfoCircularHollow, null);
    switch (priority) {
        case core_frontend_1.OutputMessagePriority.Success:
            svg = React.createElement(itwinui_icons_react_1.SvgStatusSuccess, null);
            break;
        case core_frontend_1.OutputMessagePriority.Warning:
            svg = React.createElement(itwinui_icons_react_1.SvgStatusWarning, null);
            break;
        case core_frontend_1.OutputMessagePriority.Fatal:
        case core_frontend_1.OutputMessagePriority.Error:
            svg = React.createElement(itwinui_icons_react_1.SvgStatusErrorHollow, null);
            break;
    }
    return React.createElement(itwinui_react_1.Icon, null, svg);
}
//# sourceMappingURL=InputField.js.map