/*!
 * Copyright 2017 by ChartIQ, Inc.
 * All rights reserved.
 */
import * as React from "react";
import { FEAGlobals } from "../../../common/Globals";
const DIALOG_BASE_CLASS = "dialog";
/**
 * This is a component that adds some baked in behavior that is common accross several
 * of the finsemble dialogs. Hiding/closing on blur, timing out, etc.
 */
export const FinsembleDialog = (props) => {
    let { userInputTimeout, onShowRequested, isModal, className, children } = props;
    const handleKeyDown = (e) => {
        // If the user hits escape then hide the window
        // openerMessage won't be null if data is in transit to the originating window, in which
        // case we bypass the hide() -- this is some sort of race condition from a long time ago
        // that is not fully understood
        if (e.key === "Escape" && FEAGlobals.FSBL.Clients.DialogManager.openerMessage === null) {
            FEAGlobals.finsembleWindow.hide();
        }
    };
    FEAGlobals.finsembleWindow.setAlwaysOnTop({
        alwaysOnTop: true,
    });
    if (typeof onShowRequested === "undefined") {
        throw new Error("No onShowRequested passed to FinsembleDialog. Pass onShowRequested as a property to the FinsembleDialog component.");
    }
    /*if (typeof behaviorOnResponse === "undefined") {
        behaviorOnResponse = "hide";
    }*/
    if (typeof userInputTimeout === "undefined") {
        userInputTimeout = 10000;
    }
    FEAGlobals.FSBL.Clients.DialogManager.userInputTimeout = userInputTimeout;
    //FEAGlobals.FSBL.Clients.DialogManager.behaviorOnResponse = behaviorOnResponse;
    /**
     * Registers some event listeners the first time this component is rendered.
     */
    React.useEffect(() => {
        document.body.addEventListener("keydown", handleKeyDown);
        document.body.classList.add("dialog");
        FEAGlobals.FSBL.Clients.DialogManager.registerDialogCallback(onShowRequested);
    }, []);
    const classes = className ? `${className} ${DIALOG_BASE_CLASS}` : DIALOG_BASE_CLASS;
    return React.createElement("div", { className: classes }, children);
};
//# sourceMappingURL=FinsembleDialog.js.map