import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import { flow } from 'lodash';
import { useCallback, useMemo } from 'react'; // import convertLegacyTranslationsToIntlProps from './convertLegacyTranslationsToIntlProps';

import { useLocalizeConfig } from '../useLocalizeConfig';
import { setDefaultType } from '../utils';
import legacyConfigSupport from './legacyConfigSupport';
import maybeSetElements from './maybeSetElements';
import omitNullValues from './omitNullValues';
import setElementDefaultKeys from './setElementDefaultKeys';

var useNormalizeConfig_ = function useNormalizeConfig_() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      _ref$localize = _ref.localize,
      localize = _ref$localize === void 0 ? true : _ref$localize,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'form' : _ref$type;

  var localizeConfig = useLocalizeConfig();
  return useCallback(function (config) {
    return flow([// Remove possible null values, to make default function parameters to be
    // affective.
    omitNullValues, setDefaultType(type), legacyConfigSupport, // If applicable type and elements are not defined.
    maybeSetElements, // Use element index as default key.
    setElementDefaultKeys, //convertLegacyTranslationsToIntlProps,
    localize && localizeConfig].filter(Boolean))(config);
  }, [localize, localizeConfig, type]);
};

var useNormalizeConfig = function useNormalizeConfig(options) {
  return function useNormalizeConfig(config) {
    var normalize = useNormalizeConfig_(options);
    return useMemo(function () {
      return normalize(config);
    }, [config, normalize]);
  };
};

export default useNormalizeConfig;
export var useNormalizeConfigProp = function useNormalizeConfigProp(props) {
  return _objectSpread(_objectSpread({}, props), {}, {
    config: useNormalizeConfig()(props.config)
  });
};
export var useNormalizeConfigs = function useNormalizeConfigs(options) {
  return function useNormalizeConfigs(configs) {
    var normalize = useNormalizeConfig_(options);
    return useMemo(function () {
      return configs.map(normalize);
    }, [configs, normalize]);
  };
};
//# sourceMappingURL=index.js.map