/*!
 * Copyright 2017 - 2020 by ChartIQ, Inc.
 * All rights reserved.
 */
/**
 * The Workspace Client manages all calls to load, save, rename, and delete workspaces.
 *
 * The Workspace Client uses the `windowIdentifier` parameter. <a href="/docs/productivity/componentTypesAndWindowNames">Learn more about them here</a>.
 *
 * See the <a href="/docs/productivity/Workspaces">Workspace tutorial</a> for an overview of using the Workspace Client.
 * @module WorkspaceClient
 */
/**
This is how we want our API to work going foward, the way the world does it: import { processAndSet } from "configClient"
```
export const processAndSet = () => { ... }
```

This module's single exported object gives us backward compatibility when our core code does this: import { ConfigClient } from "configClient"
and provides the object that is attached to FSBL.Clients. This export should be kept as clean and simple as possible.
```
export const ConfigClient = {
   processAndSet
}
```

The default export gives us backward compatibility where our core code does this: import ConfigClient from "configClient"
This can be eliminated when our core core is converted to normal imports as in the first example.
```
export default ConfigClient;
```
*/
import { Logger } from "./logger";
import { WORKSPACE } from "../common/constants";
import { ConfigUtilInstance as ConfigUtils } from "../common/configUtil";
import { RouterClient } from "./routerClient";
import FinsembleEvent from "../common/events/FinsembleEvent";
import PublicEventManager from "../common/events/PublicEventManager";
import { singleton } from "../common/Singleton";
import { bringWindowsToFront as bringWindowsToFront, minimizeWindows, autoArrange } from "../common/Desktop";
import { removeWindowReferenceFromActiveWorkspace, addWindowReferenceToActiveWorkspace, } from "../platform/services/workspace/workspaceAdminAPI";
import ConfigClient from "./configClient";
export { FinsembleEvent };
/**
 * @phantom Don't display in Typedoc
 */
export class WorkspaceClientController {
    constructor() {
        /**
         * In here we subscribe to the Finsemble.WorkspaceService.update topic which *should*
         * keep both the activeWorkspace and other workspace variables up to date via updates
         * published by the workspace service, which contain both the activeWorkspace
         * and other workspace names
         */
        /**
         * List of all workspaces names within the application.
         */
        this.workspaces = [];
        /**
         * Utility for managing event listeners - much like EventEmitter
         */
        this.publicEventManager = new PublicEventManager({
            name: "workspaceClient",
            sourceType: "workspace",
        });
        RouterClient.subscribe(WORKSPACE.WORKSPACE_UPDATED, (err, response) => {
            Logger.system.debug(`${WORKSPACE.WORKSPACE_UPDATED} response`, err, response);
            if (err) {
                Logger.system.error(err);
                return;
            }
            this.activeWorkspace = response.data.activeWorkspace;
            this.workspaces = response.data.workspaces;
        });
    }
}
/**
 * @ignore
 */
export const getControllerInstance = () => singleton("WorkspaceClient", WorkspaceClientController);
/**
 * Call getControllerInstance immediately to initialize the instance, otherwise at the first call the instance will not have latest data
 */
getControllerInstance();
// Helper function to handle responses from the workspace service
const serviceResponseHandler = (err, response, resolve, reject, cb) => {
    if (err) {
        reject(new Error(err));
        return cb === null || cb === void 0 ? void 0 : cb(err);
    }
    if (!response)
        response = { data: null };
    resolve(response.data);
    cb === null || cb === void 0 ? void 0 : cb(null, response.data);
};
/**
 * @language javascript, java, dotnet
 * This provides the ability to listen to workspace events.
 * The load-requested event provides a way to merge data into the workspace prior to loading.
 * The close-requested and save-requested event, allow you to perform actions prior to the actual save and close.
 * The rest of the events are informational only.
 * To tell the workspace service to wait, you must call event.wait() in less than one second.
 * Calling event.wait() will wait indefinitely.
 * After event.wait() is called, event.done() must be called to resume operation.
 * If the event is cancelable, event.cancel() may also be called after event.wait() to cancel the event.
 * To send data event.done(data) must be called, otherwise done with no data is assumed.
 *
 * ```javascript
 * // Sync examples:
 * FSBL.Clients.WorkspaceClient.addEventListener("close-requested", (event) => { doSomething(); })
 * FSBL.Clients.WorkspaceClient.addEventListener("load-requested", (event) => { const data = doSomething(); event.done(data); })
 *
 * // Async examples:
 * FSBL.Clients.WorkspaceClient.addEventListener("close-requested", async (event) => { event.wait(); await doSomething(); event.done(); })
 * FSBL.Clients.WorkspaceClient.addEventListener("load-requested", async (event) => { event.wait(); const data = await doSomething(); event.done(data); })
 * ```
 * @param event The workspace event to listen for
 * @param handler A function to handle the event
 */
export const addEventListener = (event, handler) => {
    const controller = getControllerInstance();
    controller.publicEventManager.addEventListener(event, handler);
};
/**
 * @language javascript, java, dotnet
 * Removes an event listener.
 *
 * @param event The workspace event that is listened on
 * @param handler The handler that is in effect
 */
export const removeEventListener = (event, handler) => {
    const controller = getControllerInstance();
    controller.publicEventManager.removeEventListener(event, handler);
};
/**
 * @language javascript, java, dotnet
 * Gets the currently active workspace.
 * This function is useful for setting the initial state of a menu or dialog. It is used in the toolbar component to set the initial state.
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.getActiveWorkspace((err, response) => {
 * 	// do something with the response.
 * });
 * ```
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const getActiveWorkspace = async (cb) => {
    var _a, _b;
    const controller = getControllerInstance();
    const { activeWorkspace } = controller;
    Logger.system.debug("WorkspaceClient.getActiveWorkspace");
    if (activeWorkspace) {
        Logger.system.info("WorkspaceClient.getActiveWorkspace - returning from cache");
        if (cb) {
            cb(null, {
                data: activeWorkspace,
            });
        }
        return { data: activeWorkspace };
    }
    const { response } = await RouterClient.query(WORKSPACE.API_CHANNELS.GET_ACTIVE_WORKSPACE, {});
    controller.activeWorkspace = response.data;
    const error = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.err) || response.header.error;
    if (error) {
        if (cb)
            cb(error);
        throw new Error(error);
    }
    if (cb)
        cb(null, {
            data: (_b = response.data) !== null && _b !== void 0 ? _b : {},
        });
    return { data: response.data };
};
/**
 * @language javascript, java, dotnet
 * Returns the list of saved workspaces. This function is useful for setting the initial state of a menu or dialog.
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.getWorkspaces((err, response) => {
 *   //do something with the array of workspace objects
 *   console.log(response)
 * });
 * ```
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const getWorkspaces = (cb) => {
    Logger.system.debug("WorkspaceClient.getWorkspaces");
    const getWorkspacesPromiseResolver = async (resolve, reject) => {
        RouterClient.query(WORKSPACE.API_CHANNELS.GET_WORKSPACES, {}, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(getWorkspacesPromiseResolver);
};
/**
 * @language javascript, dotnet
 * Gets workspace actions defined as constants. Allows users to filter
 * updates
 *
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const getWorkspaceActions = (cb) => {
    cb === null || cb === void 0 ? void 0 : cb(null, WORKSPACE.API_CHANNELS);
    return WORKSPACE.API_CHANNELS;
};
/**
 * @language javascript, dotnet
 * Returns a list of workspace names. This function returns the list of all the workspace.
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.getWorkspaceNames((err, response) => {
 *   console.log(JSON.stringify(response, null, 2));
 * });
 *
 *
 * Output:
 * [
 *   "Default Workspace",
 *   "Another workspace"
 * ]
 *
 * ```
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const getWorkspaceNames = (cb) => {
    Logger.system.debug("WorkspaceClient.getWorkspaceNames");
    const controller = getControllerInstance();
    const { workspaces } = controller;
    if (workspaces) {
        Logger.system.info("WorkspaceClient.getWorkspaceNames - returning from cache");
        cb === null || cb === void 0 ? void 0 : cb(null, workspaces);
        return Promise.resolve(workspaces);
    }
    const getWorkspaceNamesPromiseResolver = async (resolve, reject) => {
        RouterClient.query(WORKSPACE.API_CHANNELS.GET_WORKSPACE_NAMES, {}, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(getWorkspaceNamesPromiseResolver);
};
/**
 * @language javascript, dotnet
 * Sets the ordering of workspaces (e.g. to control the ordering of workspaces listed in a menu.)
 *
 * @param params
 * @param cb
 * @returns
 * @ignore Keep private until params can be documented
 */
export const setWorkspaceOrder = (params, cb) => {
    const { workspaces } = params;
    Logger.system.debug("WorkspaceClient.setWorkspaceOrder", params);
    const setWorkspaceOrderPromiseResolver = (resolve, reject) => {
        RouterClient.query(WORKSPACE.API_CHANNELS.SET_WORKSPACE_ORDER, workspaces || params, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(setWorkspaceOrderPromiseResolver);
};
/**
 * @language javascript, java, dotnet
 * Removes a workspace. Either the workspace object or its name must be provided.
 *
 * The following examples both remove 'My Workspace' from the main menu and the default storage tied to the application.
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.remove({
 *   name: 'My Workspace'
 * }, function(err, response) {
 * 	//You typically won't do anything here. If you'd like to do something when a workspace change happens, we suggest listening on the `Finsemble.WorkspaceService.update` channel.
 * });
 *
 * FSBL.Clients.WorkspaceClient.remove({
 * 	 workspace: {
 *     version: "1.0.0",
 *     name: 'My Workspace',
 *     type: "workspace",
 *     // ...
 *   }
 * });
 * ```
 * @param params Parameters object specifying the workspace name to remove, either directly as `name` or by passing in the `workspace` from which the name will be extracted.
 * @param params.workspace A workspace data object.
 * @param params.workspace.name The workspace name, embedded in the workspace object, that removal is requested for.
 * @param params.name The workspace name removal is requested for.
 * @param cb Callback to fire after 'Finsemble.WorkspaceService.update' is transmitted.
 */
export const remove = (params, cb) => {
    Logger.system.debug("WorkspaceClient.remove", params);
    const removePromiseResolver = async (resolve, reject) => {
        var _a;
        if (!params.name) {
            params.name = (_a = params.workspace) === null || _a === void 0 ? void 0 : _a.name;
            // we dont need to send workspace objects over the router if not needed.
            delete params.workspace;
        }
        // Cannot remove active workspace.
        const aws = (await getActiveWorkspace()).data;
        const { data } = await ConfigClient.get(["finsemble", "servicesConfig", "workspace", "permanentWorkspaces"]);
        if (data && Array.isArray(data) && data.includes(params.name)) {
            Logger.system.error(`APPLICATION LIFECYCLE:  Cannot remove permanent workspace: WorkspaceClient.remove:attempt to remove permanent workspace name:${params.name}`);
            return serviceResponseHandler("Cannot remove permanent workspace", null, resolve, reject, cb);
        }
        if (params.name === aws.name) {
            Logger.system.error(`APPLICATION LIFECYCLE:  Cannot remove active workspace: WorkspaceClient.remove:attempt to remove active workspace name:${aws.name}`);
            return serviceResponseHandler("Cannot remove active workspace", null, resolve, reject, cb);
        }
        RouterClient.query(WORKSPACE.API_CHANNELS.REMOVE, params, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(removePromiseResolver);
};
/**
 * Helper that tells us whether a workspace with this name exists.
 */
const workspaceExists = (workspaceName) => {
    const controller = getControllerInstance();
    return controller.workspaces.indexOf(workspaceName) > -1;
};
/**
 * @language javascript, java, dotnet
 * Renames the workspace with the provided name. Also removes all references in storage to the old workspace's name.
 * This method is used to rename workspaces. It is used in the main Menu component.
 *
 * :::note
 * If you attempt to rename a Workspace to a name that already exists a `({next number})` will be added to the newName.
 * :::
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.rename({
 * 	oldName: 'My Workspace',
 * 	newName: 'The best workspace',
 * 	removeOldWorkspace: true,
 * }, function(err, response) {
 * 	//Do something.
 * });
 * ```
 * @param params
 * @param params.oldName Name of workspace to rename.
 * @param params.newName What to rename the workspace to.
 * @param params.removeOldWorkspace Whether to remove references to old workspace after renaming.
 * @param params.overwriteExisting Whether to overwrite an existing workspace.
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const rename = (params, cb) => {
    Logger.system.debug("WorkspaceClient.rename", params);
    const renamePromiseResolver = (resolve, reject) => {
        if (!params.overwriteExisting && workspaceExists(params.newName)) {
            const err = "Workspace Already Exists";
            return serviceResponseHandler(err, null, resolve, reject, cb);
        }
        RouterClient.query(WORKSPACE.API_CHANNELS.RENAME, params, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(renamePromiseResolver);
};
/**
 * @language javascript, java, dotnet
 * Saves the current active workspace.
 *
 * This example persists the currently active workspace.
 * ```javascript
 * FSBL.Clients.WorkspaceClient.save(function(err) {
 * 	//Do something.
 * });
 * ```
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const save = (cb) => {
    Logger.system.debug("WorkspaceClient.save");
    const savePromiseResolver = (resolve, reject) => {
        RouterClient.query(WORKSPACE.API_CHANNELS.SAVE, {}, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(savePromiseResolver);
};
/**
 * @language javascript, java, dotnet
 * Saves the currently active workspace with the provided name.
 *
 * This example persists the currently active workspace with the provided name.
 * ```javascript
 * FSBL.Clients.WorkspaceClient.saveAs({
 * 	name: 'My Workspace',
 * }, function(err, response) {
 * 	//Do something.
 * });
 * ```
 * @param params
 * @param params.name The new name you want to save the workspace under.
 * @param params.force Whether to overwrite a workspace already saved with the provided name.
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const saveAs = (params, cb) => {
    Logger.system.debug("WorkspaceClient.saveAs", params);
    const saveAsPromiseResolver = (resolve, reject) => {
        if (!params.name) {
            return serviceResponseHandler("Invalid arguments. The required name parameter is missing.", null, resolve, reject, cb);
        }
        if (!params.force && params.name && workspaceExists(params.name)) {
            return serviceResponseHandler("Workspace Already Exists", null, resolve, reject, cb);
        }
        RouterClient.query(WORKSPACE.API_CHANNELS.SAVE_AS, params, (err, response) => {
            serviceResponseHandler(err, response, resolve, reject, cb);
        });
    };
    return new Promise(saveAsPromiseResolver);
};
/**
 * @language javascript, java, dotnet
 * Switches to a workspace.
 *
 * This example loads the workspace 'My Workspace' from the storage tied to the application.
 * ```javascript
 * FSBL.Clients.WorkspaceClient.switchTo({
 * 	name: 'My Workspace',
 * }, function(err, response) {
 * 	//Do something.
 * });
 * ```
 * @param params
 * @param params.name The name of the workspace you want to switch to.
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const switchTo = async (params, cb) => {
    Logger.system.debug("WorkspaceClient.switchTo", params);
    const { err, response } = await RouterClient.query(WORKSPACE.API_CHANNELS.SWITCH_TO, params);
    if (err) {
        if (cb)
            cb(err);
        throw new Error(err.toString());
    }
    if (cb)
        cb(err, response.data);
    return { data: response.data };
};
/**
 * Sets the stored state of a given window in the active workspace. `state` may include
 * keys for `windowData`, `componentState`, or both; the state of each key will be completely
 * overwritten by the provided state. If the update results in dirtying change, the active
 * workspace will be marked dirty (or, if auto save is on, persisted directly to storage).
 *
 * @ignore This function is only called by the Window and Assimilation services. It should be
 * moved into workspaceService/workspaceAdminAPI. But, the code uses the locally cached
 * activeWorkspace which may or may not be for legitimate performance reasons. Therefore we're
 * leaving this here until it can be safely refactored.
 */
export const setWindowState = async (params) => {
    var _a, _b;
    const controller = getControllerInstance();
    const { activeWorkspace } = controller;
    if (!activeWorkspace) {
        throw "Workspace is not yet ready";
    }
    if (!activeWorkspace.windows.includes(params.windowName)) {
        throw "Cannot set state for Window not in workspace";
    }
    Logger.system.debug("WorkspaceClient.setWindowData", params);
    const { response } = await RouterClient.query(WORKSPACE.API_CHANNELS.SET_WINDOW_STATE, params);
    return {
        ...response,
        data: (_a = response.data) !== null && _a !== void 0 ? _a : {},
        header: (_b = response.header) !== null && _b !== void 0 ? _b : {},
    };
};
/**
 * Retrieves the given window from storage, retrieving the requested state variables
 * (`"componentState"` and/or `"windowData"`). This function is calle
 * @ignore This is not used anywhere
 * @deprecated
 */
const _getWindowState = async (params) => {
    var _a, _b;
    Logger.system.deprecated("`WorkspaceClient._getWindowState()` is deprecated and will be removed in a future release. Use WorkspaceClient.getWorkspaces()");
    Logger.system.debug("WorkspaceClient.getWindowData", params);
    const { response } = await RouterClient.query(WORKSPACE.API_CHANNELS.GET_WINDOW_STATE, params);
    return {
        ...response,
        data: (_a = response.data) !== null && _a !== void 0 ? _a : {},
        header: (_b = response.header) !== null && _b !== void 0 ? _b : {},
    };
};
/**
 * @language javascript, dotnet
 * Checks to see if the workspace is dirty, i.e., if its state has been changed since the last save. If it's already dirty, the window doesn't need to compare its state to the saved state.
 *
 * This example will let you know if the active workspace is dirty.
 * ```javascript
 * FSBL.Clients.WorkspaceClient.isWorkspaceDirty(function(err, response) {
 *     if (response.data === true) {
 *         //Do something like prompt the user if they'd like to save the currently loaded workspace before switching.
 *    } else {
 *        //Workspace is clean
 *    }
 * });
 * ```
 * @param cb `cb(err,response)` with response set to true if dirty and false otherwise (when no error).
 */
export const isWorkspaceDirty = async (cb) => {
    Logger.system.debug("WorkspaceClient.isWorkspaceDirty");
    const { err, response } = await RouterClient.query(WORKSPACE.API_CHANNELS.GET_ACTIVE_WORKSPACE_DIRTY, {}, () => { });
    cb === null || cb === void 0 ? void 0 : cb(err, response);
    return response.data;
};
/**
 * @language javascript, java, dotnet
 * Creates a new workspace, returning a promise for the final name of
 * the new workspace as a string. After creation, if "switchAfterCreation" is true,
 * the new workspace becomes the active workspace.
 *
 * If the requested name already exists, a new workspace will be created
 * with the form "[name] (1)" (or "[name] (2)", etc.)
 *
 * This example creates the workspace 'My Workspace'.
 * ```javascript
 * FSBL.Clients.WorkspaceClient.createWorkspace(
 * 	"My workspace",
 *  {switchAfterCreation:true},
 *  function(err, response) {
 *		if (!err) {
 *			//Do something, such as notify the user that the workspace has been created.
 *		}
 *  }
 * );
 * ```
 * @param workspaceName Name for new workspace. If the workspaceName is empty, the workspace is given the name "Untitled." Subsequent creations with empty strings would result in "Untitled1", "Untitled2", etc.
 * @param params Optional params
 * @param params.switchAfterCreation Whether to switch to the new workspace after creating it. Defaults to true.
 * @param cb `cb(err,response)` With response, set to new workspace object if no error.
 */
export const createWorkspace = async (workspaceName, params, cb = (err, result) => {
    if (err) {
        Logger.system.error(`Error creating workspace: ${err}`);
        Logger.system.info(`Result from create workspace: ${result}`);
    }
}) => {
    params = params !== null && params !== void 0 ? params : {};
    Logger.system.log(`WorkspaceClient: Creating Workspace Request for name "${workspaceName}"`);
    const finalName = (await RouterClient.query(WORKSPACE.API_CHANNELS.NEW_WORKSPACE, {
        workspaceName,
    })).response.data;
    if (params.switchAfterCreation !== false) {
        await switchTo({ name: finalName });
    }
    const result = { workspaceName: finalName };
    cb(null, result);
    return result;
};
/**
 * @rename export
 * @language javascript, java
 * Gets a workspace definition in JSON form.
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.export({'workspaceName': 'linker'}, function(err, workspaceDefinition) {
 * 	//do something with the workspace definition
 * });
 * ```
 * @param params
 * @param params.workspaceName The name of the workspace you want to export.
 * @param cb callback(error, workspaceDefinition)
 */
export const exportWorkspace = (params, cb) => {
    Logger.system.debug("WorkspaceClient.export", params);
    const exportPromiseResolver = (resolve, reject) => {
        RouterClient.query(WORKSPACE.API_CHANNELS.EXPORT, params, (err, response) => {
            const workspaceExport = {};
            workspaceExport[params.workspaceName] = response.data;
            serviceResponseHandler(err, { data: workspaceExport }, resolve, reject, cb);
        });
    };
    return new Promise(exportPromiseResolver);
};
/**
 * @rename import
 * @language javascript, java
 * Adds a workspace definition to the list of available workspaces.
 *
 * ```javascript
 * FSBL.Clients.WorkspaceClient.import({force: false, workspaceJSONDefinition: workspaceDefinition}, function(err) {
 *		if (!err) console.log("import success.");
 * });
 * ```
 * @param params
 * @param params.workspaceJSONDefinition The JSON for the workspace definition, as exported by the User Preferences menu in Finsemble Connect.
 * @param params.force Whether to overwrite any workspace of the same name that already exists
 * @param cb `cb(err)` where the operation was successful if !err; otherwise, err carries diagnostics
 */
export const importWorkspace = async (params, cb) => {
    Logger.system.debug("WorkspaceClient.import", params);
    const result = (await RouterClient.query(WORKSPACE.API_CHANNELS.IMPORT, params)).response
        .data;
    if (result && result.err) {
        cb === null || cb === void 0 ? void 0 : cb(result.err);
        throw new Error(result.err);
    }
    cb === null || cb === void 0 ? void 0 : cb(null, result);
    return result;
};
/**
 * Saves one or more template definitions in a selected file. Note the
 * end user is prompted to identify file location during this save
 * operation. The file can optionally be imported during config
 * initialization (see importConfig) although this requires administration
 * support on the configuration/server side. The file can also be read
 * using readWorkspaceTemplateFromConfigFile();
 *
 * @param params
 * @param params.workspaceTemplateDefinition legal template definition returned by either
 * getWorkspaceTemplateDefinition() or convertWorkspaceDefinitionToTemplate()
 * @ignore This isn't used anywhere. Is it in use by customers?
 */
export const exportToFile = (params) => {
    Logger.system.info("workspaceClient.saveWorkspaceTemplateToConfigFile", params);
    const { workspaceTemplateDefinition } = params;
    if (typeof workspaceTemplateDefinition === "object") {
        const templateName = Object.keys(workspaceTemplateDefinition)[0];
        if (templateName && workspaceTemplateDefinition[templateName].templateDefinitionFlag) {
            // confirm the object is a template definition
            const exportConfig = {
                workspaceTemplates: workspaceTemplateDefinition,
            };
            ConfigUtils.promptAndSaveJSONToLocalFile(`workspaceConfig-${templateName}`, exportConfig);
        }
        else {
            Logger.system.error("workspaceClient.saveWorkspaceTemplateToConfigFile. Input is not a legal template");
        }
    }
    else {
        Logger.system.error("workspaceClient.saveWorkspaceTemplateToConfigFile: Input is not a legal object");
    }
};
/**
 * Re-export so that typedoc will associate the docs with this module
 */
export { bringWindowsToFront, minimizeWindows as minimizeAll, autoArrange } from "../common/Desktop";
/**
 * @ignore
 */
export const WorkspaceClient = {
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    saveWorkspaceTemplateToConfigFile: (params) => {
        Logger.system.deprecated("`WorkspaceClient.saveWorkspaceTemplateToConfigFile()` is deprecated and will be removed in a future release. Use WorkspaceClient.exportToFile()");
        return exportToFile(params);
    },
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    addWorkspaceDefinition: (params, cb) => {
        Logger.system.deprecated("`WorkspaceClient.addWorkspaceDefinition()` is deprecated and will be removed in a future release. Use WorkspaceClient.importWorkspace()");
        return importWorkspace(params, cb);
    },
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    getWorkspaceDefinition: (params, cb) => {
        Logger.system.deprecated("`WorkspaceClient.getWorkspaceDefinition()` is deprecated and will be removed in a future release. Use WorkspaceClient.exportWorkspace()");
        return exportWorkspace(params, cb);
    },
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    createNewWorkspace: (workspaceName, params, cb) => {
        Logger.system.deprecated("`WorkspaceClient.createNewWorkspace()` is deprecated and will be removed in a future release. Use WorkspaceClient.createWorkspace()");
        return createWorkspace(workspaceName, params, cb);
    },
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    setWorkspaces: (params, cb) => {
        Logger.system.deprecated("`WorkspaceClient.setWorkspaces()` is deprecated and will be removed in a future release. Use WorkspaceClient.setWorkspaceOrder()");
        return setWorkspaceOrder(params, cb);
    },
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    initialize: () => {
        Logger.system.deprecated("`It is no longer necessary to call WorkspaceClient.initialize().");
    },
    /**
     * For backward compatibility
     * @private
     * @deprecated
     */
    onReady: (cb) => {
        Logger.system.deprecated("It is no longer necessary to call WorkspaceClient.onReady()");
        cb === null || cb === void 0 ? void 0 : cb();
    },
    removeWindow: (params, cb) => {
        Logger.system.deprecated("`WorkspaceClient.removeWindow()` is deprecated and will be removed in a future release.");
        removeWindowReferenceFromActiveWorkspace(params, cb);
    },
    addWindow: (params, cb) => {
        Logger.system.deprecated("`WorkspaceClient.addWindow()` is deprecated and will be removed in a future release.");
        addWindowReferenceToActiveWorkspace(params, cb);
    },
    get workspaces() {
        /* this member is still in use internally. Deprecate when refactored. */
        const controller = getControllerInstance();
        return controller.workspaces;
    },
    get activeWorkspace() {
        /* this member is still in use internally. Deprecate when refactored. */
        const controller = getControllerInstance();
        return controller.activeWorkspace;
    },
    export: exportWorkspace,
    import: importWorkspace,
    exportToFile,
    createWorkspace,
    isWorkspaceDirty,
    _getWindowState,
    _setWindowState: (params) => {
        Logger.system.deprecated("`WorkspaceClient._setWindowState()` is deprecated and will be removed in a future release. Use WorkspaceClient.getWorkspaces()");
        return setWindowState(params);
    },
    switchTo,
    saveAs,
    workspaceExists: (workspaceName) => {
        Logger.system.deprecated("`WorkspaceClient.workspaceExists()` is deprecated and will be removed in a future release. Use WorkspaceClient.getWorkspaces()");
        workspaceExists(workspaceName);
    },
    save,
    rename,
    remove,
    setWorkspaceOrder,
    getWorkspaceNames,
    getWorkspaceActions,
    getWorkspaces,
    getActiveWorkspace,
    bringWindowsToFront,
    minimizeAll: minimizeWindows,
    autoArrange,
    addEventListener,
    removeEventListener,
};
/**
 * @ignore
 */
export default WorkspaceClient;
//# sourceMappingURL=workspaceClient.js.map