"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useLocalizeConfig = useLocalizeConfig;
exports.isLecacyTranslationObject = exports.translateArray = exports.translateArrayProperties = exports.translateProperties = void 0;

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

var _lodash = require("lodash");

var _react = require("react");

var _useLocalize = require("./useLocalize");

var translateProperties = ['title', 'name', 'label', 'default', 'description', 'help', 'patternDescription', 'placeholder', 'yes', 'no', 'content', 'successText', 'enumNames', 'textDefault', 'consentTitle', 'consentMessage', 'labelError', 'logoAlt', 'confirmTitle'];
exports.translateProperties = translateProperties;
var translateArrayProperties = ['choices', 'elements', 'scaleMarks', 'calcTableColumns'];
exports.translateArrayProperties = translateArrayProperties;
var translateArray = ['tableColumns', 'rowTitles'];
exports.translateArray = translateArray;

var isLecacyTranslationObject = function isLecacyTranslationObject(value, key) {
  return typeof value === 'object' && translateProperties.includes(key);
};

exports.isLecacyTranslationObject = isLecacyTranslationObject;

function useLocalizeConfig() {
  var localize = (0, _useLocalize.useLocalize)();
  return (0, _react.useCallback)(function localizeConfig(config) {
    var translatedConfig = (0, _lodash.omitBy)(config, isLecacyTranslationObject);
    var translate = (0, _lodash.pickBy)(config, isLecacyTranslationObject); // Proposal for translated config values
    // if (Object.keys(translate).length) {
    //   translatedConfig.intl = translate;
    // }

    return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, (0, _lodash.mapValues)(translatedConfig, function (value, key) {
      return translateArrayProperties.includes(key) ? value === null || value === void 0 ? void 0 : value.map(function (value) {
        return typeof value === 'object' ? localizeConfig(value) : value;
      }) : translateArray.includes(key) ? value === null || value === void 0 ? void 0 : value.map(function (value) {
        return typeof value === 'object' ? localize(value) : value;
      }) : value;
    })), (0, _lodash.mapValues)(translate, localize));
  }, [localize]);
}
//# sourceMappingURL=useLocalizeConfig.cjs.map