import { useObjectRef } from '@cloudbeaver/core-blocks' ; import { useService } from '@cloudbeaver/core-di' ; import type { IDataContext } from '../DataContext/IDataContext' ; import type { IMenu } from './IMenu' ; import type { IMenuItem } from './MenuItem/IMenuItem' ; import { MenuService } from './MenuService' ; import { useMenuContext } from './useMenuContext' ; export interface IMenuData { menu : IMenu ; context : IDataContext ; isAvailable : ( ) => boolean ; getItems : ( ) => IMenuItem [ ] ; } export function useMenu ( menu , menuContext ? ) { const menuService = useService ( MenuService ) ; const context = useMenuContext ( menu , menuContext ) ; return useObjectRef ( ( ) => ( { isAvailable ( ) { return menuService . isMenuAvailable ( this . context ) ; } , getItems ( ) { return menuService . getMenu ( this . context ) ; } , } ) , { menu , context , } , [ 'isAvailable' , 'getItems' ] ) ; }