"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useNormalizeConfigs = exports.useNormalizeConfigProp = exports["default"] = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _lodash = require("lodash");

var _react = require("react");

var _useLocalizeConfig = require("../useLocalizeConfig");

var _utils = require("../utils");

var _legacyConfigSupport = _interopRequireDefault(require("./legacyConfigSupport"));

var _maybeSetElements = _interopRequireDefault(require("./maybeSetElements"));

var _omitNullValues = _interopRequireDefault(require("./omitNullValues"));

var _setElementDefaultKeys = _interopRequireDefault(require("./setElementDefaultKeys"));

// import convertLegacyTranslationsToIntlProps from './convertLegacyTranslationsToIntlProps';
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 = (0, _useLocalizeConfig.useLocalizeConfig)();
  return (0, _react.useCallback)(function (config) {
    return (0, _lodash.flow)([// Remove possible null values, to make default function parameters to be
    // affective.
    _omitNullValues["default"], (0, _utils.setDefaultType)(type), _legacyConfigSupport["default"], // If applicable type and elements are not defined.
    _maybeSetElements["default"], // Use element index as default key.
    _setElementDefaultKeys["default"], //convertLegacyTranslationsToIntlProps,
    localize && localizeConfig].filter(Boolean))(config);
  }, [localize, localizeConfig, type]);
};

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

var _default = useNormalizeConfig;
exports["default"] = _default;

var useNormalizeConfigProp = function useNormalizeConfigProp(props) {
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), {}, {
    config: useNormalizeConfig()(props.config)
  });
};

exports.useNormalizeConfigProp = useNormalizeConfigProp;

var useNormalizeConfigs = function useNormalizeConfigs(options) {
  return function useNormalizeConfigs(configs) {
    var normalize = useNormalizeConfig_(options);
    return (0, _react.useMemo)(function () {
      return configs.map(normalize);
    }, [configs, normalize]);
  };
};

exports.useNormalizeConfigs = useNormalizeConfigs;
//# sourceMappingURL=index.cjs.map