// Gather actionNames from all registered modules for hot-key mapping

import { modules } from 'stripes-loader'; // eslint-disable-line
import stripesComponents from '@folio/stripes-components/package.json';

function addKeys(register, list) {
  if (list) {
    for (const actionName of list) {
      register[actionName] = true;
    }
  }
}

export default function gatherActions() {
  const allActions = {};

  for (const key of Object.keys(modules)) {
    const set = modules[key];
    for (const key2 of Object.keys(set)) {
      const module = set[key2];
      addKeys(allActions, module.actionNames);
    }
  }

  addKeys(allActions, stripesComponents.stripes.actionNames);

  return Object.keys(allActions);
}

// Gather actionNames from all registered modules for hot-key mapping

import { modules } from 'stripes-loader'; // eslint-disable-line
import stripesComponents from '@folio/stripes-components/package.json';

function addKeys(moduleName, register, list) {
  if (list) {
    for (const actionName of list) {
      if (!register[actionName]) register[actionName] = [];
      register[actionName].push(moduleName);
    }
  }
}

export default function gatherActions() {
  const allActions = {};

  for (const key of Object.keys(modules)) {
    const set = modules[key];
    for (const key2 of Object.keys(set)) {
      const module = set[key2];
      addKeys(module.module, allActions, module.actionNames);
    }
  }

  addKeys('stripes-components', allActions, stripesComponents.stripes.actionNames);

  return Object.keys(allActions);
}

Gather names of modules that use action-names
Gather names of modules that use action-names

At present, we then immeduately discard that information, since we
only return the array of _keys_ of the `allActions` register. But we
may change the API of `stripes.allActions` down the line to return the
whole register.
