import React, { useEffect, useState } from "react";
import { Menu } from "../../menu/Menu";
import { MenuItem } from "../../menu/MenuItem";
import ComponentList from "./components/componentList";
import { storeManager } from "./stores/appLauncherStore";
import "./appLauncher.css";
import { FEAGlobals } from "../../../../common/Globals";
/**
 * The "app" button that launches the AppLauncher menu from the toolbar.
 * The app launcher lists all configured Finsemble applications.
 *
 * @param {object} [options]
 * @param {boolean} [options.enableQuickComponents=false] DEPRECATED: Set to true to allow users to create their own components
 * @param {string} [options.title] The title of the menu, as viewed in the toolbar
 * @param {string[]} [options.componentFilter] Custom list of menu items to display
 * @param {boolean} [options.suppressFavorites=false]
 */
export const StaticAppLauncherMenu = (options) => {
    var _a, _b, _c, _d;
    const [initialized, setInitialized] = useState(false);
    const onInitialized = () => {
        setInitialized(true);
    };
    useEffect(() => {
        storeManager.addInitializedListener(onInitialized);
        storeManager.initialize();
        // Focus on the window when it is shown so that a click elsewhere will trigger a blur.
        FEAGlobals.finsembleWindow.addEventListener("shown", () => {
            FEAGlobals.finsembleWindow.focus();
        });
        if (options.enableQuickComponents) {
            FEAGlobals.FSBL.Clients.Logger.system.error("QuickComponents are deprecated and will be removed in a future release.");
        }
        return () => {
            storeManager.removeInitializedListener(onInitialized);
        };
    }, []);
    // @deprecated - Quick Components will be removed in a future version
    const openQuickComponent = () => {
        // FEAGlobals.FSBL.Clients.LauncherClient.spawn("QuickComponentForm", { monitor: "mine" });
        FEAGlobals.FSBL.Clients.DialogManager.open("QuickComponentForm", {}, () => { });
    };
    const completeProps = {
        ...options,
        width: (_a = options.width) !== null && _a !== void 0 ? _a : 300,
        id: (_b = options.id) !== null && _b !== void 0 ? _b : "AppLauncherMenu",
        title: (_c = options.title) !== null && _c !== void 0 ? _c : "Apps",
        className: (_d = options.className) !== null && _d !== void 0 ? _d : "menu-portal app-launcher",
    };
    return (React.createElement(Menu, { ...completeProps },
        options.enableQuickComponents ? (React.createElement("div", { className: "menu-secondary" },
            React.createElement(MenuItem, { onClick: openQuickComponent }, "New App"))) : null,
        initialized && (React.createElement(ComponentList, { componentFilter: options.componentFilter, suppressFavorites: options.suppressFavorites }))));
};
//# sourceMappingURL=StaticAppLauncherMenu.js.map