import * as React from "react";
import { useEffect, useState } from "react";
import glueFactory from "@interopio/desktop";
import { MenuItem } from "../menu/MenuItem";
import { openQuitConfirmationDialog } from "../shared/openQuitConfirmationDialog";
import { FEAGlobals } from "../../../common/Globals";
/**
 * A menu item that opens the user preferences menu when clicked.
 */
export const Preferences = () => (React.createElement(MenuItem, { onClick: () => {
        FEAGlobals.FSBL.Clients.LauncherClient.showWindow({
            componentType: "UserPreferences",
        }, {
            monitor: "mine",
            left: "center",
            top: "center",
        });
    } }, "Preferences"));
/**
 * A menu item that opens the system log window when clicked.
 */
export const SystemLog = () => {
    if (typeof FEAGlobals.FSBL.SystemManagerClient.showSystemLog === "function") {
        return (React.createElement(MenuItem, { onClick: () => {
                FEAGlobals.FSBL.SystemManagerClient.showSystemLog();
                // close the menu
                FEAGlobals.finsembleWindow.blur();
            } }, "System Log"));
    }
    else {
        // There isn't an equivalent for SystemLog in io.cd
        return React.createElement(React.Fragment, null);
    }
};
/**
 * A menu item that opens the Central Logger when clicked.
 */
export const CentralLogger = () => (React.createElement(MenuItem, { onClick: () => {
        FEAGlobals.FSBL.Clients.RouterClient.transmit("CentralConsole-Show", true);
    } }, "Central Logger"));
/**
 * A menu item that opens the io.Connect devtools (interop viewer, context viewer, etc)
 */
export const DevTools = () => {
    const [glue, setGlue] = useState(null);
    useEffect(() => {
        // If running in iocd then set up the glue library
        if (window.glue42gd) {
            glueFactory().then((myGlue) => {
                setGlue(myGlue);
            });
        }
    }, []);
    const onClick = () => {
        const app = glue === null || glue === void 0 ? void 0 : glue.appManager.application("DevTools");
        app === null || app === void 0 ? void 0 : app.start();
    };
    return glue ? React.createElement(MenuItem, { onClick: onClick }, "IO.Connect Dev Tools") : React.createElement(React.Fragment, null);
};
/**
 * A menu item that opens Finsemble documentation in a browser when clicked.
 */
export const Documentation = () => (React.createElement(MenuItem, { onClick: () => {
        FEAGlobals.FSBL.Clients.DialogManager.spawnDialog({
            name: "Documentation",
            width: 750,
            url: "https://documentation.finsemble.com/tutorial-finsemble-user-guide.html",
        }, {}, () => { });
    } }, "Documentation"));
/**
 * A menu item that restarts the Finsemble application when clicked.
 */
export const Restart = () => React.createElement(MenuItem, { onClick: () => openQuitConfirmationDialog("Restart") }, "Restart");
/**
 * A menu item that resets the Finsemble application.
 * The reset clears out all the user data of the application when clicked.
 */
export const Reset = () => (React.createElement(MenuItem, { onClick: () => {
        FEAGlobals.FSBL.Clients.StorageClient.clearCache(() => {
            FEAGlobals.FSBL.restartApplication({ forceRestart: true });
        });
    } }, "Reset"));
/**
 * A menu item that quits the Finsemble application when clicked.
 */
export const Quit = () => React.createElement(MenuItem, { onClick: openQuitConfirmationDialog }, "Quit");
//# sourceMappingURL=System.js.map