// eslint-disable-next-line @typescript-eslint/no-unused-vars namespace OutSystems.OSUI.Patterns.BottomSheetAPI { const _bottomSheetItemsMap = new Map(); //BottomSheet.uniqueId -> BottomSheet obj /** * Function that will change the property of a given BottomSheet Id. * * @param bottomSheetId ID of the BottomSheet where the property will be changed. * @param propertyName Property name that will be updated * @param propertyValue Value that will be set to the property * @returns the API response envelope as a JSON string: `{ code, isSuccess, message, value? }` */ export function ChangeProperty(bottomSheetId: string, propertyName: string, propertyValue: unknown): string { const result = OutSystems.OSUI.Utils.CreateApiResponse({ errorCode: ErrorCodes.BottomSheet.FailChangeProperty, callback: () => { const _bottomSheetItem = GetBottomSheetItemById(bottomSheetId); _bottomSheetItem.changeProperty(propertyName, propertyValue); }, }); return result; } /** * Create the new BottomSheetItem instance and add it to the bottomSheetItemsMap * * @param bottomSheetId ID of the Pattern that a new instance will be created. * @param configs Configurations for the Pattern in JSON format. * @returns the BottomSheet instance */ export function Create( bottomSheetId: string, configs: string | Configs ): OSFramework.OSUI.Patterns.BottomSheet.IBottomSheet { if (_bottomSheetItemsMap.has(bottomSheetId)) { throw new Error('There is already an BottomSheet registered under id: ' + bottomSheetId); } const _bottomSheetItem = new OSFramework.OSUI.Patterns.BottomSheet.BottomSheet( bottomSheetId, OSFramework.OSUI.Helper.ParseConfigs(configs) ); _bottomSheetItemsMap.set(bottomSheetId, _bottomSheetItem); return _bottomSheetItem; } /** * Function that will dispose the instance of the given BottomSheetItem Id * * @param bottomSheetId The id of the BottomSheet element * @returns the API response envelope as a JSON string: `{ code, isSuccess, message, value? }` */ export function Dispose(bottomSheetId: string): string { const result = OutSystems.OSUI.Utils.CreateApiResponse({ errorCode: ErrorCodes.BottomSheet.FailDispose, callback: () => { const _bottomSheetItem = GetBottomSheetItemById(bottomSheetId); _bottomSheetItem.dispose(); _bottomSheetItemsMap.delete(_bottomSheetItem.uniqueId); }, }); return result; } /** * Fucntion that will return the Map with all the BottomSheet instances at the page * * @returns Array */ export function GetAllBottomSheetItemsMap(): Array { return OSFramework.OSUI.Helper.MapOperation.ExportKeys(_bottomSheetItemsMap); } /** * Function that gets the instance of BottomSheet, by a given ID. * * @param bottomSheetId ID of the BottomSheet that will be looked for. * @returns the BottomSheet instance */ export function GetBottomSheetItemById(bottomSheetId: string): OSFramework.OSUI.Patterns.BottomSheet.IBottomSheet { return OSFramework.OSUI.Helper.MapOperation.FindInMap( 'BottomSheet', bottomSheetId, _bottomSheetItemsMap ) as OSFramework.OSUI.Patterns.BottomSheet.IBottomSheet; } /** * Function that will initialize the pattern instance. * * @param bottomSheetId ID of the BottomSheetItem that will be initialized. * @returns the BottomSheet instance */ export function Initialize(bottomSheetId: string): OSFramework.OSUI.Patterns.BottomSheet.IBottomSheet { const _bottomSheetItem = GetBottomSheetItemById(bottomSheetId); _bottomSheetItem.build(); return _bottomSheetItem; } /** * Function to open this pattern * * @param bottomSheetId The id of the BottomSheet element * @returns the API response envelope as a JSON string: `{ code, isSuccess, message, value? }` */ export function Open(bottomSheetId: string): string { const result = OutSystems.OSUI.Utils.CreateApiResponse({ errorCode: ErrorCodes.BottomSheet.FailOpen, callback: () => { const _bottomSheetItem = GetBottomSheetItemById(bottomSheetId); _bottomSheetItem.open(); }, }); return result; } /** * Function to close this pattern * * @param bottomSheetId The id of the BottomSheet element * @returns the API response envelope as a JSON string: `{ code, isSuccess, message, value? }` */ export function Close(bottomSheetId: string): string { const result = OutSystems.OSUI.Utils.CreateApiResponse({ errorCode: ErrorCodes.BottomSheet.FailClose, callback: () => { const _bottomSheetItem = GetBottomSheetItemById(bottomSheetId); _bottomSheetItem.close(); }, }); return result; } /** * Function to register a callback on this pattern * * @param bottomSheetId The id of the BottomSheet element * @param eventName The name of the event to register the callback for * @param callback The function invoked when the event fires * @returns the API response envelope as a JSON string: `{ code, isSuccess, message, value? }` */ export function RegisterCallback( bottomSheetId: string, eventName: EventName, callback: OSFramework.OSUI.GlobalCallbacks.OSGeneric ): string { const result = OutSystems.OSUI.Utils.CreateApiResponse({ errorCode: ErrorCodes.BottomSheet.FailRegisterCallback, callback: () => { const bottomSheet = GetBottomSheetItemById(bottomSheetId); bottomSheet.registerCallback(eventName, callback); }, }); return result; } }