/*---------------------------------------------------------------------------------------------
 * 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 "./InputField.scss";
import * as React from "react";
import { OutputMessagePriority } from "@itwin/core-frontend";
import { RelativePosition } from "@itwin/appui-abstract";
import { Icon as CoreIcon, MessageRenderer, Popup } from "@itwin/core-react";
import { SvgClose, SvgInfoCircularHollow, SvgStatusErrorHollow, SvgStatusSuccess, SvgStatusWarning, } from "@itwin/itwinui-icons-react";
import { Icon } from "@itwin/itwinui-react";
import { MessageManager } from "../messages/MessageManager.js";
/** 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.
 */
export class InputFieldMessage extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {
            message: "",
            isVisible: false,
            priority: 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 @typescript-eslint/no-deprecated
        React.createElement(Popup, { isOpen: isVisible, position: 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(MessageRenderer, { className: "uifw-popup-message-brief", message: message }),
                            detailedMessage && (
                            // eslint-disable-next-line @typescript-eslint/no-deprecated
                            React.createElement(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(CoreIcon, { iconSpec: React.createElement(SvgClose, null) }))))));
    }
    componentDidMount() {
        MessageManager.onInputFieldMessageAddedEvent.addListener(this._handleInputFieldMessageAddedEvent);
        MessageManager.onInputFieldMessageRemovedEvent.addListener(this._handleInputFieldMessageRemovedEvent);
    }
    componentWillUnmount() {
        MessageManager.onInputFieldMessageAddedEvent.removeListener(this._handleInputFieldMessageAddedEvent);
        MessageManager.onInputFieldMessageRemovedEvent.removeListener(this._handleInputFieldMessageRemovedEvent);
    }
}
function FieldIcon({ priority }) {
    let svg = React.createElement(SvgInfoCircularHollow, null);
    switch (priority) {
        case OutputMessagePriority.Success:
            svg = React.createElement(SvgStatusSuccess, null);
            break;
        case OutputMessagePriority.Warning:
            svg = React.createElement(SvgStatusWarning, null);
            break;
        case OutputMessagePriority.Fatal:
        case OutputMessagePriority.Error:
            svg = React.createElement(SvgStatusErrorHollow, null);
            break;
    }
    return React.createElement(Icon, null, svg);
}
//# sourceMappingURL=InputField.js.map