function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import memoize from 'lodash/memoize';
// eslint-disable-next-line import/prefer-default-export
export const indexData = memoize(dataList => {
  const indexedDataList = [];
  dataList.forEach((row, idx) => {
    const children = [];

    if (row.metadata && row.metadata.children && row.metadata.children.length > 0) {
      row.metadata.children.forEach((child, childIdx) => {
        children.push(_extends({}, child, {
          metadata: _extends({}, child.metadata, {
            originalIndex: childIdx,
            isChild: true
          })
        }));
      });
    }

    indexedDataList.push(_extends({}, row, {
      metadata: _extends({}, row.metadata, {
        children,
        originalIndex: idx,
        isChild: false
      })
    }));
  });
  return indexedDataList;
});