import { Menu } from './tenant.interface';

export function findMenu(menues: readonly Menu[], menuCode: string): Menu | undefined {
  for (const menu of menues) {
    if (menu.code === menuCode) {
      return menu;
    }

    const submenu = findMenu(menu.submenues ?? [], menuCode);

    if (submenu) {
      return submenu;
    }
  }

  return undefined;
}
