"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");
/** StandardMessageBox React component displays a standard icon, message text and a standard button set in the lower right.
 * @public
 */
class StandardMessageBox extends React.PureComponent {
    constructor(props) {
        super(props);
        this._handleButton = (buttonType) => {
            this._closeDialog(() => {
                // istanbul ignore else
                if (this.props.onResult)
                    this.props.onResult(buttonType);
            });
        };
        this._handleCancel = () => {
            this._closeDialog(() => {
                // istanbul ignore else
                if (this.props.onResult)
                    this.props.onResult(core_frontend_1.MessageBoxValue.Cancel);
            });
        };
        this._closeDialog = (followUp) => {
            this.setState((_prevState) => ({
                opened: false,
            }), () => {
                UiFramework_1.UiFramework.dialogs.modal.close();
                followUp();
            });
        };
        this.state = {
            opened: this.props.opened,
        };
    }
    render() {
        const buttonCluster = new Array();
        switch (this.props.messageBoxType) {
            case core_frontend_1.MessageBoxType.Ok:
            case core_frontend_1.MessageBoxType.LargeOk:
                buttonCluster.push({ type: appui_abstract_1.DialogButtonType.OK, onClick: () => { this._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: () => { this._handleButton(core_frontend_1.MessageBoxValue.Ok); } });
                buttonCluster.push({ type: appui_abstract_1.DialogButtonType.Cancel, onClick: () => { this._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: () => { this._handleButton(core_frontend_1.MessageBoxValue.Yes); } });
                buttonCluster.push({ type: appui_abstract_1.DialogButtonType.No, onClick: () => { this._handleButton(core_frontend_1.MessageBoxValue.No); } });
                if (core_frontend_1.MessageBoxType.YesNoCancel === this.props.messageBoxType)
                    buttonCluster.push({ type: appui_abstract_1.DialogButtonType.Cancel, onClick: () => { this._handleButton(core_frontend_1.MessageBoxValue.Cancel); } });
                break;
        }
        let severity = appui_abstract_1.MessageSeverity.None;
        switch (this.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;
        }
        return (React.createElement(core_react_1.MessageBox, { className: this.props.className, style: { zIndex: DialogManagerBase_1.DialogManagerBase.topZIndex, ...this.props.style }, opened: this.state.opened, title: this.props.title, severity: severity, buttonCluster: buttonCluster, onClose: this._handleCancel, onEscape: this._handleCancel }, this.props.children));
    }
}
exports.StandardMessageBox = StandardMessageBox;
//# sourceMappingURL=StandardMessageBox.js.map