/**
 * This file contains LauncherClient exports that are now deprecated
 */
import { getMyWindowIdentifier as getMyWindowIdentifierUtil } from "../common/util";
import { Logger } from "../clients/logger";
import { RouterClient } from "../clients/routerClient";
import SystemManagerClient from "../common/systemManagerClient";
import { deprecatedGetActiveAndPendingWindowNames } from "../deprecated/deprecatedFunctions";
import { getWhichMonitorClientSide } from "../common/Monitors";
import { Startup } from "../clients/Startup/Startup";
import { FinsembleWindow } from "../common/FinsembleWindow";
/**
 * Dynamically registers a component with the Launcher Service for the current Finsemble session. This method registers a given component in a component manifest, making it available to an app launcher component. Note: Components registered in this way are removed at the end of Finsemble's current session.
 *
 * @param params.componentType The key of the component in the component's config.
 * @param params.manifest This should be a component manifest, i.e., a component configuration file like <i>components.json</i>.
 * @param cb The callback to be invoked after the method completes successfully.
 * @deprecated
 */
export const registerComponent = async (params, cb) => {
    await SystemManagerClient.waitForStartup("windowService");
    const { err, response } = await RouterClient.query("LauncherService.registerComponent", params);
    cb === null || cb === void 0 ? void 0 : cb(err, response.data);
    return { err, data: response.data };
};
/**
 * Unregisters a component with the Launcher Service.
 *
 * @param params.componentType The key of the component in the component's config.
 * @param cb
 * @deprecated
 */
export const unRegisterComponent = async (params, cb) => {
    if (!params.componentType) {
        const error = "No componentType provided";
        cb === null || cb === void 0 ? void 0 : cb(error);
        return { err: error };
    }
    await SystemManagerClient.waitForStartup("windowService");
    const { err, response } = await RouterClient.query("LauncherService.unRegisterComponent", params);
    cb === null || cb === void 0 ? void 0 : cb(err, response.data);
    return { err, data: response.data };
};
/**
 * @deprecated as of 5.2.0, will be removed in a future release.
 *
 * Convenience function to get a monitor descriptor for a given windowIdentifier, or for the
 * current window.
 *
 * @param windowIdentifier The window to find the monitor for. Current window if undefined.
 * @param cb Returns a monitor descriptor (optional or use returned Promise)
 * @returns A promise that resolves to a monitorInfo
 * @ignore
 */
export const getMonitor = async (windowIdentifier, cb) => {
    Logger.system.deprecated("This method is deprecated and will be removed in a future release. Use the method getMonitorInfo instead.");
    return getWhichMonitorClientSide(RouterClient, { windowIdentifier }, cb);
};
/**
 * Gets all active or pending window names. Active windows have completed spawning.  Pending windows have been spawned but haven't yet completed.
 *
 * @param cb Callback returns an array of window names (as does the resolved Promise).
 * @ignore
 * @deprecated Move to workspaceService where this code is actually used
 */
export const getActiveAndPendingWindowNames = (cb = Function.prototype) => {
    Logger.deprecated("LauncherClient.getActiveAndPendingWindowNames is deprecated and will be removed");
    return deprecatedGetActiveAndPendingWindowNames(RouterClient, cb);
};
/**
 * Get list of windows objects that haven't finished spawning
 * Individual window objects are not full windows,
 * they contain the window name and a few other attributes
 *
 * @returns Object
 * @ignore
 * @deprecated Move to workspaceService where this code is actually used
 */
export const getPendingWindows = async () => {
    Logger.deprecated("LauncherClient.getPendingWindows is deprecated and will be removed");
    await SystemManagerClient.waitForStartup("windowService");
    const { err, response } = await RouterClient.query("Launcher.getPendingWindows", {});
    return { err, data: response.data };
};
/**
 * Gets components that can receive specific data types. Returns an object containing componentTypes mapped to a list of dataTypes they can receive. This is based on the "advertiseReceivers" property in a component's config.
 *
 * ```javascript
 * FSBL.Client.LauncherClient.getComponentsThatCanReceiveDataTypes({ dataTypes: ['chartiq.chart', 'salesforce.contact']}, function(err, response) {
 * 	//Response contains: {'chartiq.chart': ['Advanced Chart'], 'salesforce.contact': ['Salesforce Contact']}
 * })
 * ```
 * @param params.dataTypes An array of data types. Looks for components that can receive those data types.
 * @param cb The callback to be invoked after the method completes successfully.
 * @deprecated
 * @ignore
 */
export const getComponentsThatCanReceiveDataTypes = (params, cb = Function.prototype) => {
    Logger.deprecated("LauncherClient.getComponentsThatCanReceiveDataTypes is deprecated and will be removed");
    const promiseResolver = (resolve) => {
        if (!params || !params.dataTypes) {
            const err = "Invalid params. Expected: {dataTypes: string[]}";
            cb(err);
            return resolve({ err });
        }
        if (!Array.isArray(params.dataTypes)) {
            params.dataTypes = [params.dataTypes];
        }
        RouterClient.query("LauncherService.getComponentsThatCanReceiveDataTypes", params, (err, response) => {
            cb(err, response.data);
            resolve({ err, data: response.data });
        });
    };
    return new Promise(promiseResolver);
};
/**
 * Minimizes all but a specific list or group of windows. Either groupName or windowList must be specified.
 *
 * ```javascript
 * LauncherClient.hyperFocus({ windowList: ['AdvancedChart-123-123', 'Symphony-Chat-234-234']}, function(err, response) {
 *
 * })
 * ```
 * @param params
 * @param params.windowList Optional. An array of window names or window identifiers. Not to be used with componentType.
 * @param params.groupName Optional. The name of a window group to hyperFocus.
 * @param params.componentType Optional. The Component Type to hyperFocus. Not to be used with windowList.
 * @deprecated as of 4.0.0, may be removed in the future
 * @ignore
 */
export const hyperFocus = async (params, cb) => {
    Logger.system.deprecated("hyperFocus is deprecated as of version 4.0.0. This functionality may be removed in a future release");
    if (params.windowList && !Array.isArray(params.windowList)) {
        params.windowList = [params.windowList];
    }
    const myWindowIdentifier = await getMyWindowIdentifierUtil();
    if (!params.windowList && !params.groupName && !params.componentType) {
        params.windowList = myWindowIdentifier ? [myWindowIdentifier] : [];
    }
    await SystemManagerClient.waitForStartup("windowService");
    await RouterClient.transmit("LauncherService.hyperFocus", params);
    cb === null || cb === void 0 ? void 0 : cb();
};
/**
 * Create Window group
 * @param params
 * @param params.groupName The name of the window group to create
 * @param params.windowList An array of window names or window identifiers to add to the group. Optional.
 * @param cb callback to be called upon group creation
 *
 * @ignore
 * @deprecated
 */
export const createWindowGroup = (params, cb = Function.prototype) => {
    Logger.deprecated("LauncherClient.createWindowGroup is deprecated and will be removed");
    if (params.windowList && !Array.isArray(params.windowList)) {
        params.windowList = [params.windowList];
        delete params.groupName;
    }
    const promiseResolver = async (resolve) => {
        if (!params.groupName) {
            const err = "Invalid Parameters";
            resolve({ err });
            cb(err);
            return;
        }
        await SystemManagerClient.waitForStartup("windowService");
        RouterClient.query("LauncherService.createWindowGroup", params, (err, response) => {
            cb(err, response);
            resolve({ err, data: response });
        });
    };
    return new Promise(promiseResolver);
};
/**
 * Add Windows to group
 * @param params
 * @param params.groupName The name of the window group
 * @param params.windowList An array of window names or window identifiers to add to the group.
 * @param cb callback to be called upon group creation
 *
 * @ignore
 * @deprecated
 */
export const addWindowsToGroup = (params, cb = Function.prototype) => {
    Logger.deprecated("LauncherClient.addWindowsToGroup is deprecated and will be removed");
    const promiseResolver = async (resolve) => {
        if (!params.groupName || !params.windowList) {
            const err = "Invalid Parameters";
            resolve({ err });
            cb(err);
            return;
        }
        if (params.windowList && !Array.isArray(params.windowList)) {
            params.windowList = [params.windowList];
        }
        await SystemManagerClient.waitForStartup("windowService");
        RouterClient.query("LauncherService.addWindowsToGroup", params, (err, response) => {
            cb(err, response);
            resolve({ err, data: response });
        });
    };
    return new Promise(promiseResolver);
};
/**
 * Remove Windows from group
 * @param params
 * @param params.groupName The name of the window group
 * @param params.windowList An array of window names or window identifiers to remove from the group.
 * @param cb callback to be called upon group creation
 *
 * @ignore
 * @deprecated
 */
export const removeWindowsFromGroup = (params, cb = Function.prototype) => {
    Logger.deprecated("LauncherClient.removeWindowsFromGroup is deprecated and will be removed");
    const promiseResolver = async (resolve) => {
        if (!params.groupName || !params.windowList) {
            const err = "Invalid Parameters";
            resolve({ err });
            cb(err);
            return;
        }
        if (params.windowList && !Array.isArray(params.windowList)) {
            params.windowList = [params.windowList];
        }
        await SystemManagerClient.waitForStartup("windowService");
        RouterClient.query("LauncherService.removeWindowsFromGroup", params, (err, response) => {
            cb(err, response);
            resolve({ err, data: response });
        });
    };
    return new Promise(promiseResolver);
};
/**
 * Get Window Groups that a window belongs to. If no windowIdentifier is specified, gets  the groups of the current window.
 * @param params
 * @param params.windowIdentifier Optional. If not specified uses current window
 * @param cb callback with a list of groups
 *
 * @ignore
 * @deprecated
 */
export const getGroupsForWindow = (params, cb = Function.prototype) => {
    Logger.deprecated("LauncherClient.getGroupsForWindow is deprecated and will be removed");
    if (typeof params === "function") {
        cb = params;
        params = null;
    }
    const promiseResolver = async (resolve) => {
        if (!params || !params.windowIdentifier) {
            const { windowName } = Startup.getInstance().getStartupData();
            const { wrap } = await FinsembleWindow.getInstance({ name: windowName });
            wrap.getComponentState({ field: "finsemble:windowGroups" }, (err, groups) => {
                resolve({ err, data: groups });
                cb(err, groups);
            });
            return;
        }
        await SystemManagerClient.waitForStartup("windowService");
        RouterClient.query("LauncherService.getGroupsForWindow", params, (err, response) => {
            resolve({ err, data: response.data });
            cb(err, response.data);
        });
    };
    return new Promise(promiseResolver);
};
/**
 * @param params
 * @param params.windowIdentifier Optional. Current window is assumed if not specified.
 * @param params.groupNames List of group names to add window to. Groups will be created if they do not exist.
 * @param cb
 * @ignore
 * @deprecated
 */
export const addToGroups = async (params, cb) => {
    var _a;
    Logger.deprecated("LauncherClient.addToGroups is deprecated and will be removed");
    const myWindowIdentifier = await getMyWindowIdentifierUtil();
    params.windowIdentifier = (_a = params.windowIdentifier) !== null && _a !== void 0 ? _a : myWindowIdentifier;
    await SystemManagerClient.waitForStartup("windowService");
    const { err } = await RouterClient.query("LauncherService.addWindowToGroups", params);
    cb === null || cb === void 0 ? void 0 : cb(err);
    return { err };
};
//# sourceMappingURL=deprecatedlauncherClient.js.map