"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 Dialog
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandardMessageBox = void 0;
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 DialogManagerBase_1 = require("./DialogManagerBase");
const UiFramework_1 = require("../UiFramework");
const itwinui_react_1 = require("@itwin/itwinui-react");
const components_react_1 = require("@itwin/components-react");
/** StandardMessageBox React component displays a standard icon, message text and a standard button set in the lower right.
 * @public
 * @deprecated in 4.15.0. Use {@link https://itwinui.bentley.com/docs/dialog iTwinUI Dialog} instead.
 */
// eslint-disable-next-line deprecation/deprecation
function StandardMessageBox(props) {
    const [isOpen, setIsOpen] = React.useState(props.opened);
    let severity = appui_abstract_1.MessageSeverity.None;
    switch (props.iconType) {
        case core_frontend_1.MessageBoxIconType.NoSymbol:
            severity = appui_abstract_1.MessageSeverity.None;
            break;
        case core_frontend_1.MessageBoxIconType.Information:
            severity = appui_abstract_1.MessageSeverity.Information;
            break;
        case core_frontend_1.MessageBoxIconType.Question:
            severity = appui_abstract_1.MessageSeverity.Question;
            break;
        case core_frontend_1.MessageBoxIconType.Warning:
            severity = appui_abstract_1.MessageSeverity.Warning;
            break;
        case core_frontend_1.MessageBoxIconType.Critical:
            severity = appui_abstract_1.MessageSeverity.Error;
            break;
        case core_frontend_1.MessageBoxIconType.Success:
            severity = appui_abstract_1.MessageSeverity.Success;
            break;
    }
    const handleButton = (buttonType) => {
        closeDialog(() => {
            if (props.onResult)
                props.onResult(buttonType);
        });
    };
    const handleCancel = () => {
        closeDialog(() => {
            if (props.onResult)
                props.onResult(core_frontend_1.MessageBoxValue.Cancel);
        });
    };
    const closeDialog = (followUp) => {
        setIsOpen(false);
        UiFramework_1.UiFramework.dialogs.modal.close();
        followUp();
    };
    return (React.createElement(itwinui_react_1.Dialog, { isOpen: isOpen, style: { zIndex: DialogManagerBase_1.DialogManagerBase.topZIndex, ...props.style }, className: props.className, onClose: handleCancel, closeOnEsc: true, closeOnExternalClick: false, preventDocumentScroll: true },
        React.createElement(itwinui_react_1.Dialog.Backdrop, null),
        React.createElement(itwinui_react_1.Dialog.Main, { style: { width: 512 }, "data-testid": "message-box-dialog-container" },
            React.createElement(itwinui_react_1.Dialog.TitleBar, { titleText: props.title }),
            React.createElement(itwinui_react_1.Dialog.Content, null,
                React.createElement(core_react_1.MessageContainer, { severity: severity }, props.children)),
            React.createElement(itwinui_react_1.Dialog.ButtonBar, null,
                React.createElement(DialogButtons, { messageBoxType: props.messageBoxType, handleButton: handleButton })))));
}
exports.StandardMessageBox = StandardMessageBox;
function DialogButtons(props) {
    const buttonCluster = new Array();
    switch (props.messageBoxType) {
        case core_frontend_1.MessageBoxType.Ok:
        case core_frontend_1.MessageBoxType.LargeOk:
            buttonCluster.push({
                type: appui_abstract_1.DialogButtonType.OK,
                onClick: () => {
                    props.handleButton(core_frontend_1.MessageBoxValue.Ok);
                },
            });
            break;
        case core_frontend_1.MessageBoxType.OkCancel:
        case core_frontend_1.MessageBoxType.MediumAlert:
            buttonCluster.push({
                type: appui_abstract_1.DialogButtonType.OK,
                onClick: () => {
                    props.handleButton(core_frontend_1.MessageBoxValue.Ok);
                },
            });
            buttonCluster.push({
                type: appui_abstract_1.DialogButtonType.Cancel,
                onClick: () => {
                    props.handleButton(core_frontend_1.MessageBoxValue.Cancel);
                },
            });
            break;
        case core_frontend_1.MessageBoxType.YesNo:
        case core_frontend_1.MessageBoxType.YesNoCancel:
            buttonCluster.push({
                type: appui_abstract_1.DialogButtonType.Yes,
                onClick: () => {
                    props.handleButton(core_frontend_1.MessageBoxValue.Yes);
                },
            });
            buttonCluster.push({
                type: appui_abstract_1.DialogButtonType.No,
                onClick: () => {
                    props.handleButton(core_frontend_1.MessageBoxValue.No);
                },
            });
            if (core_frontend_1.MessageBoxType.YesNoCancel === props.messageBoxType)
                buttonCluster.push({
                    type: appui_abstract_1.DialogButtonType.Cancel,
                    onClick: () => {
                        props.handleButton(core_frontend_1.MessageBoxValue.Cancel);
                    },
                });
            break;
    }
    return buttonCluster.map((button, index) => {
        return React.createElement(DialogButton, { button: button, key: index });
    });
}
function DialogButton({ button }) {
    const { translate } = (0, components_react_1.useTranslation)();
    let buttonText = "";
    let usePrimaryStyleType = false;
    switch (button.type) {
        case appui_abstract_1.DialogButtonType.OK:
            buttonText = translate("dialog.ok");
            usePrimaryStyleType = true;
            break;
        case appui_abstract_1.DialogButtonType.Retry:
            buttonText = translate("dialog.retry");
            usePrimaryStyleType = true;
            break;
        case appui_abstract_1.DialogButtonType.Yes:
            buttonText = translate("dialog.yes");
            usePrimaryStyleType = true;
            break;
        case appui_abstract_1.DialogButtonType.No:
            buttonText = translate("dialog.no");
            break;
        case appui_abstract_1.DialogButtonType.Cancel:
            buttonText = translate("dialog.cancel");
            break;
        case appui_abstract_1.DialogButtonType.Close:
            buttonText = translate("dialog.close");
            break;
        case appui_abstract_1.DialogButtonType.Next:
            buttonText = translate("dialog.next");
            usePrimaryStyleType = true;
            break;
        case appui_abstract_1.DialogButtonType.Previous:
            buttonText = translate("dialog.previous");
            usePrimaryStyleType = true;
            break;
    }
    return (React.createElement(itwinui_react_1.Button, { styleType: usePrimaryStyleType ? "high-visibility" : undefined, onClick: button.onClick }, buttonText));
}
//# sourceMappingURL=StandardMessageBox.js.map