"use strict";

exports.__esModule = true;
exports.useStyles = exports.default = exports.compareTranslateStrings = 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(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
(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(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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 = exports.useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    elementContainer: {
      marginBottom: theme.spacing(1.5)
    }
  };
});
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 = exports.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;
};
var _default = _react.default.memo(Translations, compareTranslateStrings);
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(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);
})();