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';
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) {
// For now, navigating to specific apps can lead to errors even the app can be naviagted to successfully.
Logger.w(WarningType.Navigation, `Navigation to FP app ${appName} failed`);
TComponents.Popup_A.warning(
`${ExceptionIdMap.FailedToNavigateToApp}-${TComponents.Component_A.t(
`framework:${ExceptionIdMap.FailedToNavigateToApp}.title`,
{appNmae: appName},
)}`,
TComponents.Component_A.t(`framework:${ExceptionIdMap.FailedToNavigateToApp}.causes`),
);
return;
}
};
})();
interactionApi.constructedInteraction = true;
};
if (typeof API.constructedInteraction === 'undefined') {
factoryApiInteraction(API);
}
export default API;
export {factoryApiInteraction};