/**
 * Factory to retrieve data related to navigation (Sidebar, Footer and page navigation)
 */

/**
 * @name getNavigationItem
 * @description Mock data for navigation menu item
 * @param {boolean} submenu include submenu into the navigation item
 * @param {number} id the id will be added to the menu and sub-menu
 * @return {object} with navigation module
 */
function getNavigationItem(submenu = false, id) {
  const navigationItem = {
    title: `title ${id}`,
    value: `/menu_${id}`,
    image: `logo_${id}`,
  };

  if (submenu) {
    navigationItem.children = [
      {
        title: `submenu ${id}`,
        value: `/submenu_${id}`,
      },
    ];
  }

  return navigationItem;
}

/**
 * @name getNavigationModule
 * @description Mock data for test navigation menu with multiple items with submenu option, the id will be the item position
 * @param {number} menuItems amount of items on the navigation
 * @param {boolean} submenu include submenu into the navigation items
 * @return {object} with navigation
 */
export function getNavigationModule(menuItems = 1, submenu = false, navigationCode = 'nav_1') {
  const navigation = {
    menu_short_code: navigationCode,
    children: [],
  };

  for (let i = 1; i <= menuItems; i += 1) {
    const id = `${navigationCode}_${i}`;
    const navigationItem = getNavigationItem(submenu, id);
    navigation.children.push(navigationItem);
  }

  return navigation;
}

/**
 * @name getNavigationMenus
 * @description Mock data for test navigation menus with multiple menus
 * @param {number} menuItems amount of menus
 * @param {boolean} submenu include submenu into the navigation items
 * @return {Object} with navigation and menuList
 */
export function getNavigationMenus(menuItems = 1, navigationItems = 1, submenu = false) {
  const menu = {
    menuList: [],
    navigation: {
      modules: [],
    },
  };

  for (let i = 1; i <= menuItems; i += 1) {
    const code = `nav_${i}`;
    menu.menuList.push(code);
    const navigation = getNavigationModule(navigationItems, submenu, code);
    menu.navigation.modules.push(navigation);
  }

  return menu;
}
