/// <reference path="./sigApi.ApiBase.d.ts" />
/// <reference path="./sigApi.Menu.d.ts" />
/// <reference path="./sigApi.MenuControl.d.ts" />

declare namespace SigApi {
    interface ApiMenuManager extends ApiBase {
        /**
         * Returns the Menu Object identified by the given menuId.
         * @param {number|string} menuId Menu Index (number) or Menu Name (string); unique Menu identification
         * @returns {Menu|null} Menu object, if menuId is valid menu Index or menu Name. Null, if menuId is invalid parameter.
         */
        getMenu(menuId: number | string): Menu | null
        /**
         * Adds a Menu
         * @param {MenuBlueprint} menuBlueprint
         * @returns {Menu} Returns the added menu
         */
        addMenu(menuBlueprint: object): Menu
        /**
         * Removes a Menu
         * @param {number|string} menuId Menu Index (number) or Menu Name (string); unique Menu identification
         * @returns {boolean} Returns true, if the Menu has been removed
         */
        removeMenu(menuId: number | string): boolean
        /**
         * Shows the Menu control identified by the given menuId or menu name.
         * @param {number|string} menuId Menu Index (number) or Menu Name (string); unique Menu identification
         * @param {HTMLElement} [instanceMenuInput=undefined] The instance of the Menu-Input control
         * @param {string} [dataPointPropertyName=undefined] The property name of the bound Data Point (e.g. 'value')
         * @param {number} [posX=undefined] Opening position of the menu on the X-axis
         * @param {number} [posY=undefined] Opening position of the menu on the Y-axis
         * @param {number} [scaleX=undefined] Scale factor along X-axis of the parent component
         * @param {number} [scaleY=undefined] Scale factor along Y-axis of the parent component
         * @param {number} [rotation=undefined] Rotation of the parent component
         * @param {number} [minWidth=undefined] Minimal width of the Menu control 
         * @param {number} [minHeight=undefined] Minimal height of the Menu control
         * @param {number} [maxWidth=undefined] Maximal width of the Menu control
         * @param {number} [maxHeight=undefined] Maximal height of the Menu control
         * @param {string} [direction=undefined] Opening direction regarding the Menu-Input: "down" or "up" 
         * @param {Function} [renderContainerCallback=undefined] Render callback function for the Menu container, i.e. `div` element
         * @param {Function} [renderMenuCallback=undefined] Render callback for the Menu list, i.e. `ul` element 
         * @param {Function} [renderItemCallback=undefined] Render callback for the Menu Item, i.e. `li` element
         * @returns {Promise} JavaScript Promise. The promise is resolved when no error occurred. The boolean parameter of the fulfillment function is true, if the menu was opened successfully, false if not. 
         * The promise is rejected when an error occurred. (e.g. when a non-existing menu ID was passed)
         */
        show(
            menuId: number | string,
            instanceMenuInput?: HTMLElement,
            dataPointPropertyName?: string,
            posX?: number,
            posY?: number,
            scaleX?: number,
            scaleY?: number,
            rotation?: number,
            minWidth?: number,
            minHeight?: number,
            maxWidth?: number,
            maxHeight?: number,
            direction?: string,
            renderContainerCallback?: (id: string, data: MenuControlRenderContainerData) => MenuControlRenderContainerResult,
            renderMenuCallback?: (id: string, data: MenuControlRenderMenuData) => MenuControlRenderMenuResult,
            renderItemCallback?: (id: string, data: MenuControlRenderItemData) => MenuControlRenderItemResult,
        ): Promise<boolean>
        /**
         *  Executes submit actions for the Menu Item identified by the given menuItemId according to its properties:
         *  * It updates Data Point value if a DP is bound to the Menu-Input and menu-item. 
         *  * It executes a function block, if it is defined in the Menu Item property 'On submit'
         *  * It closes or keeps open the Menu according to the Menu Item property "Keep open" 
         * @param {string} menuItemId instanceId of the Menu Item.
         * @returns {Promise} JavaScript Promise. The promise is resolved when all submit actions were executed by Runtime successfully (update of a Data point, execution of a function block and closing of the menu). 
         * It is rejected when an error occurs.(No open menu, menu item with the passed ID was not found or submit() of the menu item not allowed)
         */
        submit(menuItemId: string): Promise<void>
        /**
         * Hides the current Menu component by calling sig-control-menu.hide() method. No submit action is executed.
         */
        cancel(): void
        /**
         * Registers a callback that renders the menu container. See 'Menu Render Callbacks' in the documentation.
         * The callback is called during control-menu show process.
         * @param {Function} callback The callback function.
         */
        registerGlobalRenderContainerCallback(callback: (id: string, data: MenuControlRenderContainerData) => MenuControlRenderContainerResult): void
        /**
         * Registers a callback that renders the menu. See 'Menu Render Callbacks' in the documentation.
         * The callback is called during control-menu show process.
         * @param {Function} callback The callback function.
         */
        registerGlobalRenderMenuCallback(callback: (id: string, data: MenuControlRenderMenuData) => MenuControlRenderMenuResult): void
        /**
         * Registers a callback that renders the menu item. See 'Menu Render Callbacks' in the documentation.
         * The callback is called during control-menu show process.
         * @param {Function} callback The callback function.
         */
        registerGlobalRenderItemCallback(callback: (id: string, data: MenuControlRenderItemData) => MenuControlRenderItemResult): void
        /**
         * Returns the Menu Item having DP value as the passed value, from the Menu identified by the passed menuId.
         * If two or more Menu Items have the same DP value the first found is returned. 
         * @param {*} value Value of the Data Point bound to the Menu-Input
         * @param {number|string} menuId  Menu Index (number) or Menu Name (string); unique Menu identification
         * @returns {Promise<object|null>} JavaScript Promise that is resolved if no error occurs. 
         * The argument of the fulfillment function is an Object that describes the menu item of the menu passed in parameter with the data point value passed in parameter. 
         * The fulfillment argument can be null if no item such item was found. The promise is rejected if an error occurs (e.g. invalid menuId passed)
         * 
         * Result object structure of the resolved promise parameter:
         * ```
         *     {
         *         instanceId: <string>,
         *         properties: {
         *             menu: [
         *                 {
         *                     name: <string>,
         *                     value: <number|string|boolean>,
         *                     src: <number>,
         *                     dest: <number>
         *                 }
         *             ],
         *             item: []
         *         },
         *         items: [
         *             {
         *                 instanceId: <string>,
         *                 properties: {},
         *                 items: []
         *             }
         *         ]
         *     }
         * ```
         */
        getMenuItemFromValue(value: any, menuId: number | string): Promise<any>
        /**
         * Returns the Menu Item identified by the given menuItemId.
         * This function is expected to be called by render callbacks to provide
         * additional information on the menuItem.
         * @param {string} menuItemId The menuItem instanceId provided in the data structure (show parameter).
         * @returns {MenuItem|null} The menu item object or null, if no menu item with such menuItemId is found.
         */
        getMenuItemFromId(menuItemId: string): MenuItem | null
        /**
         * Returns the Menu Item identified by the given menuItemIndex.
         * @param {number} menuItemIndex The menuItem index provided by {@link MenuItem} getIndex()
         * @returns {MenuItem|null} The menu item object or null, if no menu item with such menuItemIndex is found.
         */
        getMenuItemFromMenuItemIndex(menuItemIndex: number): MenuItem | null
        /**
         * Function to check if parameter object is a instanceof Menu.
         * This function can be used without importing the type Menu to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof Menu, else false
         */
        instanceofMenu(object: any): boolean
        /**
         * Function to check if parameter object is a instanceof MenuItem.
         * This function can be used without importing the type MenuItem to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof MenuItem, else false
         */
        instanceofMenuItem(object: any): boolean
    }
}
