import API from './ecosystem-base.js';
import {Logger} from './../function/log-helper.js';
import {WarningType} from '../information/informationCode.js';
import {ErrorCode, ExceptionIdMap} from './../exception/exceptionDesc.js';
import {appendDataToErrInstance} from '../utils/utils.js';
const factoryApiInteraction = function (interactionApi) {
const logModule = 'ecosystem-interaction';
/**
* API.INTERACTION provides interfaces for FP application-level interaction operations, such as navigating between different apps within the FlexPendant environment.
* @alias API.INTERACTION
* @namespace
*/
interactionApi.INTERACTION = new (function () {
/**
* Navigate to another FlexPendant app
* @alias navigateToApp
* @memberof API.INTERACTION
* @param {string} appName
* @param {string} message
* @example
* // navigate to the I/O app without message
* await API.INTERACTION.navigateToApp('I/O','')
* // navigate to the JoyStick page in Jog App
* await API.INTERACTION.navigateToApp('Jog','navigateToPage = JoystickJog & url = None')
*/
this.navigateToApp = async (appName, message = '') => {
try {
await App.Interaction.sendNavigateToRequest({AppName: appName, Message: message});
} catch (e) {
if (typeof e == 'string' && e.includes("'appNavigateTo' not found.")) {
// This is a hard way to handle
return;
}
// For now, navigating to specific apps can lead to errors even the app can be naviagted to successfully.
const errInstance = new Error(ErrorCode.FailedToNavigateToApp, {cause: e});
appendDataToErrInstance(errInstance, {severity: 'warning', msgParams: {appName}});
throw errInstance;
}
};
})();
interactionApi.constructedInteraction = true;
};
if (typeof API.constructedInteraction === 'undefined') {
factoryApiInteraction(API);
}
export default API;
export {factoryApiInteraction};