"use strict";

exports.__esModule = true;
exports.default = exports.TranslationInput = exports.ShowButtonChevron = exports.ShowButton = exports.TranslationWrapper = exports.TranslationField = exports.LanguageLabel = void 0;

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

var _reactRedux = require("react-redux");

var _styledComponents = _interopRequireDefault(require("styled-components"));

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

var _Icon = _interopRequireDefault(require("../../Icon"));

var _Text = _interopRequireDefault(require("../../Text"));

var _locale = require("../../../selectors/locale");

var _useToggle3 = _interopRequireDefault(require("../../../hooks/useToggle"));

var _Text2 = require("./Text");

var _FieldButtons = require("./FieldButtons");

var _excluded = ["lang", "message", "onChange", "required"],
    _excluded2 = ["update", "value", "initShowAll", "required", "moreLabel"];

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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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 _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

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; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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 LanguageLabel = _styledComponents.default.label.withConfig({
  displayName: "Translation__LanguageLabel",
  componentId: "sc-1w4od1i-0"
})(["flex:0 0 auto;min-width:55px;border-right:1px solid ", ";padding:5px 10px;background-color:#eaeaea;margin-right:0;"], (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"));

exports.LanguageLabel = LanguageLabel;

var TranslationField = function TranslationField(_ref) {
  var lang = _ref.lang,
      _ref$message = _ref.message,
      message = _ref$message === void 0 ? "" : _ref$message,
      onChange = _ref.onChange,
      required = _ref.required,
      props = _objectWithoutProperties(_ref, _excluded);

  return /*#__PURE__*/_react.default.createElement(_FieldButtons.ButtonWrapper, {
    invalid: required && !message
  }, /*#__PURE__*/_react.default.createElement(LanguageLabel, null, lang), /*#__PURE__*/_react.default.createElement(_Text2.FormInput, _extends({
    value: message,
    onChange: onChange
  }, props)));
};

exports.TranslationField = TranslationField;
TranslationField.displayName = "TranslationField";

var TranslationWrapper = _styledComponents.default.div.withConfig({
  displayName: "Translation__TranslationWrapper",
  componentId: "sc-1w4od1i-1"
})(["display:flex;flex-direction:column;& > *{margin-top:10px;}& >:first-child{margin-top:0;}"]);

exports.TranslationWrapper = TranslationWrapper;

var ShowButton = _styledComponents.default.div.attrs(function () {
  return {
    role: "button"
  };
}).withConfig({
  displayName: "Translation__ShowButton",
  componentId: "sc-1w4od1i-2"
})(["align-self:flex-end;cursor:pointer;"]);

exports.ShowButton = ShowButton;
var ShowButtonChevron = (0, _styledComponents.default)(_Icon.default).attrs(function (props) {
  return {
    id: (0, _utils.getThemeProp)(["icons", "indicators", "down"], "chevron-down")(props)
  };
}).withConfig({
  displayName: "Translation__ShowButtonChevron",
  componentId: "sc-1w4od1i-3"
})(["font-size:10px;margin-right:5px;color:", ";"], (0, _utils.getThemeProp)(["colors", "application", "base"], "#000"));
exports.ShowButtonChevron = ShowButtonChevron;

var TranslationInput = function TranslationInput(_ref2) {
  var update = _ref2.update,
      _ref2$value = _ref2.value,
      value = _ref2$value === void 0 ? {} : _ref2$value,
      initShowAll = _ref2.initShowAll,
      required = _ref2.required,
      _ref2$moreLabel = _ref2.moreLabel,
      moreLabel = _ref2$moreLabel === void 0 ? "[more]" : _ref2$moreLabel,
      props = _objectWithoutProperties(_ref2, _excluded2);

  var cultures = (0, _utils.unwrapImmutable)((0, _reactRedux.useSelector)(_locale.orderedCultureList));
  var handlers = (0, _react.useMemo)(function () {
    return cultures.reduce(function (handlers, lang) {
      handlers[lang] = function (event) {
        update(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, lang, event.target.value)));
      };

      return handlers;
    }, {});
  }, [update, cultures, value]);

  var _useToggle = (0, _useToggle3.default)(initShowAll),
      _useToggle2 = _slicedToArray(_useToggle, 2),
      showAll = _useToggle2[0],
      toggle = _useToggle2[1];

  return /*#__PURE__*/_react.default.createElement(TranslationWrapper, null, cultures.map(function (lang, index) {
    return !index || showAll ? /*#__PURE__*/_react.default.createElement(TranslationField, _extends({
      key: lang,
      lang: lang,
      message: value[lang],
      onChange: handlers[lang],
      required: required
    }, props)) : null;
  }), !showAll && cultures.length > 1 ? /*#__PURE__*/_react.default.createElement(ShowButton, {
    onClick: toggle
  }, /*#__PURE__*/_react.default.createElement(ShowButtonChevron, null), /*#__PURE__*/_react.default.createElement(_Text.default, {
    message: moreLabel
  })) : null);
};

exports.TranslationInput = TranslationInput;

__signature__(TranslationInput, "useSelector{}\nuseMemo{handlers}\nuseToggle{[showAll, toggle]}", function () {
  return [_reactRedux.useSelector, _useToggle3.default];
});

__signature__(TranslationInput, "useSelector{}\nuseMemo{handlers}\nuseToggle{[showAll, toggle]}", function () {
  return [_reactRedux.useSelector, _useToggle3.default];
});

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

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

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(LanguageLabel, "LanguageLabel", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(TranslationField, "TranslationField", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(TranslationWrapper, "TranslationWrapper", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(ShowButton, "ShowButton", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(ShowButtonChevron, "ShowButtonChevron", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(TranslationInput, "TranslationInput", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.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(LanguageLabel, "LanguageLabel", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(TranslationField, "TranslationField", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(TranslationWrapper, "TranslationWrapper", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(ShowButton, "ShowButton", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(ShowButtonChevron, "ShowButtonChevron", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(TranslationInput, "TranslationInput", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/Form/Inputs/Translation.js");
})();

;

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