/*---------------------------------------------------------------------------------------------
* 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
 */
import * as React from "react";
import { MessageBoxIconType, MessageBoxType, MessageBoxValue } from "@itwin/core-frontend";
import { DialogButtonType, MessageSeverity } from "@itwin/appui-abstract";
import { MessageBox } from "@itwin/core-react";
import { DialogManagerBase } from "./DialogManagerBase";
import { UiFramework } from "../UiFramework";
/** StandardMessageBox React component displays a standard icon, message text and a standard button set in the lower right.
 * @public
 */
export 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(MessageBoxValue.Cancel);
            });
        };
        this._closeDialog = (followUp) => {
            this.setState((_prevState) => ({
                opened: false,
            }), () => {
                UiFramework.dialogs.modal.close();
                followUp();
            });
        };
        this.state = {
            opened: this.props.opened,
        };
    }
    render() {
        const buttonCluster = new Array();
        switch (this.props.messageBoxType) {
            case MessageBoxType.Ok:
            case MessageBoxType.LargeOk:
                buttonCluster.push({ type: DialogButtonType.OK, onClick: () => { this._handleButton(MessageBoxValue.Ok); } });
                break;
            case MessageBoxType.OkCancel:
            case MessageBoxType.MediumAlert:
                buttonCluster.push({ type: DialogButtonType.OK, onClick: () => { this._handleButton(MessageBoxValue.Ok); } });
                buttonCluster.push({ type: DialogButtonType.Cancel, onClick: () => { this._handleButton(MessageBoxValue.Cancel); } });
                break;
            case MessageBoxType.YesNo:
            case MessageBoxType.YesNoCancel:
                buttonCluster.push({ type: DialogButtonType.Yes, onClick: () => { this._handleButton(MessageBoxValue.Yes); } });
                buttonCluster.push({ type: DialogButtonType.No, onClick: () => { this._handleButton(MessageBoxValue.No); } });
                if (MessageBoxType.YesNoCancel === this.props.messageBoxType)
                    buttonCluster.push({ type: DialogButtonType.Cancel, onClick: () => { this._handleButton(MessageBoxValue.Cancel); } });
                break;
        }
        let severity = MessageSeverity.None;
        switch (this.props.iconType) {
            case MessageBoxIconType.NoSymbol:
                severity = MessageSeverity.None;
                break;
            case MessageBoxIconType.Information:
                severity = MessageSeverity.Information;
                break;
            case MessageBoxIconType.Question:
                severity = MessageSeverity.Question;
                break;
            case MessageBoxIconType.Warning:
                severity = MessageSeverity.Warning;
                break;
            case MessageBoxIconType.Critical:
                severity = MessageSeverity.Error;
                break;
            case MessageBoxIconType.Success:
                severity = MessageSeverity.Success;
                break;
        }
        return (React.createElement(MessageBox, { className: this.props.className, style: { zIndex: 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));
    }
}
//# sourceMappingURL=StandardMessageBox.js.map