/// <reference path="./sigApi.PropertyObject.d.ts" />
declare namespace SigApi {
    interface MenuControlConfig {
        /** The menu defintion @see MenuControlDefinition*/
        menuDefinition: MenuControlDefinition,
        /** The partent node (domRef) of the menu. This is the menu (input) control (usually a sig-control-menu-input). */
        parent: HTMLElement | null
        /** 
         * Name of the datapoint viewmodel property of the menu (input) control (usually a sig-control-menu-input).
         * If null, the datapoint property configured at the menu is used.
         */
        propName: string | null
        /** The horizontal scale factor of the menu */
        scaleX: number
        /** The vertical scale factor of the menu */
        scaleY: number
        /** The horizontal (left) position of the menu */
        posX: number
        /** The vertical (top) position of the menu */
        posY: number
        /** The minimal width of the menu */
        minWidth: number | null
        /** The minimal height of the menu */
        minHeight: number | null
        /** The maximal width of the menu */
        maxWidth: number | null
        /** The maximal height of the menu */
        maxHeight: number | null
        /** The rotation of the menu */
        rotation: number
        /** The opening direction of the menu input*/
        direction: 'down' | 'up' | 'none' | '' | null
        /** Callback function to render a single menu item */
        renderItem: ((id: string, data: MenuControlRenderItemData) => MenuControlRenderItemResult) | null
        /** Callback function to render the menu itself. */
        renderMenu: ((id: string, data: MenuControlRenderMenuData) => MenuControlRenderMenuResult) | null
        /** Callback function to render the menu container. */
        renderContainer: ((id: string, data: MenuControlRenderContainerData) => MenuControlRenderContainerResult) | null
    }

    interface MenuControlDefinition {
        /** The instance id of the currently opened menu */
        instanceId: String
        /** An array of menu items @see MenuControlItem */
        items: MenuControlItem[]
        /** All item and menu properties @see MenuControlProperties */
        properties: MenuControlProperties
    }

    interface MenuControlItem {
        /** The instance id of the menu item */
        instanceId: string
        /** All item and menu properties @see MenuControlProperties */
        properties: MenuControlProperties
        /** if true, the item is marked as selected */
        selected: boolean
        /** If true, the item contains selected items */
        containsSelected: boolean
    }

    interface MenuControlProperties {
        /** An array with all item properties @see PropertyObject */
        item: PropertyObject[],
        /** An array with all menu properties @see PropertyObject */
        menu: PropertyObject[]
    }

    interface MenuControlRenderContainerData {
        /** The menu configuration @see MenuControlConfig */
        parameters: MenuControlConfig
        /** An array of all menu items */
        items: MenuControlItem[]
        /**An array of all menu properties */
        properties: MenuControlProperties
    }

    interface MenuControlRenderMenuData extends MenuControlRenderContainerData {
        // nothing for now.
    }

    interface MenuControlRenderItemData extends MenuControlRenderContainerData {
        /** The menu level relative of the menu's root */
        level: number
        /** The position of the menu item within the menu */
        position: number
        /** If true, the item is at the first position */
        firstItem: boolean
        /** If true, the item is at the last position  */
        lastItem: boolean
    }

    interface MenuControlRenderContainerResult {
        /** The node to render */
        node: HTMLElement
        /** An object of css key/value pairs to apply to the node @see cssObj*/
        cssObj?: cssObject
    }

    interface MenuControlRenderMenuResult extends MenuControlRenderContainerResult {
        positionMenuCallback?: (
            /** The domRef of the menu */
            menu: HTMLElement,
            /** The data used to render the menu @see MenuControlRenderMenuData */
            data: MenuControlRenderMenuData) => void
        handleClickCallback?: (
            /** The native javascript click event */
            e: globalThis.Event,
            /** The domRef of the clicked <li> item */
            item: HTMLElement,
            /** The domRef of the click ul */
            ul: HTMLElement,
            /** The domRef of the clicked submenu */
            submenu: HTMLElement) => void
    }

    interface MenuControlRenderItemResult extends MenuControlRenderContainerResult {
        // Nothing for now
    }

    type cssObject = {
        /** A css attribute in camelcase notation like 'zIndex' and its value */
        [key: string]: string
    }
}
