"use strict";

exports.__esModule = true;
exports.default = exports.compareTranslateStrings = exports.useStyles = void 0;

var _react = _interopRequireWildcard(require("react"));

var _reactIntl = require("react-intl");

var _styles = require("@material-ui/core/styles");

var _CollapsableList = _interopRequireDefault(require("../CollapsableList"));

var _collapsableListProps = _interopRequireDefault(require("../collapsableListProps"));

var _Inputs = require("../../Inputs");

var _sharedMessages = _interopRequireDefault(require("../../../../sharedMessages"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    elementContainer: {
      marginBottom: theme.spacing(1.5)
    }
  };
});
exports.useStyles = useStyles;

var Translations = function Translations(_ref) {
  var cultures = _ref.cultures,
      defaultCulture = _ref.defaultCulture,
      _ref$value = _ref.value,
      value = _ref$value === void 0 ? {} : _ref$value,
      update = _ref.update,
      _ref$disabled = _ref.disabled,
      disabled = _ref$disabled === void 0 ? false : _ref$disabled,
      errors = _ref.errors,
      _ref$inputAttributes = _ref.inputAttributes,
      inputAttributes = _ref$inputAttributes === void 0 ? {} : _ref$inputAttributes;
  var classes = useStyles();
  var collapsibleListProps = new _collapsableListProps.default();
  collapsibleListProps.set(_collapsableListProps.default.propNames.hasMessage, true);
  collapsibleListProps.set(_collapsableListProps.default.propNames.openMessage, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.showMoreLanguages));
  collapsibleListProps.set(_collapsableListProps.default.propNames.closeMessage, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.showFewerLanguages));
  collapsibleListProps.set(_collapsableListProps.default.propNames.expandPosition, "right");
  collapsibleListProps.set(_collapsableListProps.default.propNames.containerWidth, "unset");
  var handlers = (0, _react.useMemo)(function () {
    return cultures.reduce(function (handlers, lang) {
      handlers[lang] = function (fieldValue) {
        return update(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, lang, fieldValue)));
      };

      return handlers;
    }, {});
  }, [update, cultures, value]);
  var elementList = cultures.sort(function (ca, cb) {
    if (ca === defaultCulture) return -1;
    if (cb === defaultCulture) return 1;
    return 0;
  }).map(function (lang) {
    var inputProps = new _Inputs.InputBaseProps();
    inputProps.set(_Inputs.InputBaseProps.propNames.label, lang);
    inputProps.set(_Inputs.InputBaseProps.propNames.value, value[lang]);
    inputProps.set(_Inputs.InputBaseProps.propNames.update, handlers[lang]);
    inputProps.set(_Inputs.InputBaseProps.propNames.disabled, disabled);
    inputProps.set(_Inputs.InputBaseProps.propNames.error, errors == null ? void 0 : errors[lang]);
    inputProps.set(_Inputs.InputBaseProps.propNames.inputAttributes, inputAttributes);
    return /*#__PURE__*/_react.default.createElement("div", {
      key: lang,
      className: classes.elementContainer
    }, /*#__PURE__*/_react.default.createElement(_Inputs.InputBase, {
      inputProps: inputProps
    }));
  });

  var _elementList = _toArray(elementList),
      defaultElement = _elementList[0],
      otherElements = _elementList.slice(1);

  return /*#__PURE__*/_react.default.createElement(_CollapsableList.default, {
    collapsableListProps: collapsibleListProps,
    defaultElement: defaultElement,
    otherElements: otherElements
  });
};

__signature__(Translations, "useStyles{classes}\nuseMemo{handlers}", function () {
  return [useStyles];
});

__signature__(Translations, "useStyles{classes}\nuseMemo{handlers}", function () {
  return [useStyles];
});

var compareTranslateStrings = function compareTranslateStrings(prev, next) {
  var _next$cultures;

  return !((_next$cultures = next.cultures) != null && _next$cultures.some(function (c) {
    return (prev.value && prev.value[c]) !== (next.value && next.value[c]);
  })) && prev.errors === next.errors && prev.update === next.update;
};

exports.compareTranslateStrings = compareTranslateStrings;

var _default = _react.default.memo(Translations, compareTranslateStrings);

var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
  reactHotLoader.register(Translations, "Translations", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
  reactHotLoader.register(compareTranslateStrings, "compareTranslateStrings", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
  reactHotLoader.register(Translations, "Translations", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
  reactHotLoader.register(compareTranslateStrings, "compareTranslateStrings", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();