Liferay.Loader.define("depot-web@1.0.90/js/Languages.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/alert', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/modal', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', './LanguagesList.es', './ManageLanguages.es', '../css/Languages.scss'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

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

    var _alert = _interopRequireDefault(require("@frontend-taglib-clay$clayui/alert"));

    var _form = require("@frontend-taglib-clay$clayui/form");

    var _modal = require("@frontend-taglib-clay$clayui/modal");

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _LanguagesList = _interopRequireDefault(require("./LanguagesList.es"));

    var _ManageLanguages = _interopRequireDefault(require("./ManageLanguages.es"));

    require("../css/Languages.scss");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (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 _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_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 _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    var getLocalesInputValue = function getLocalesInputValue(arr) {
      return arr.map(function (_ref) {
        var localeId = _ref.localeId;
        return localeId;
      }).join(',');
    };

    function move(arr, from, to) {
      var clonedArr = _toConsumableArray(arr);

      var removedItem = clonedArr.splice(from, 1)[0];
      clonedArr.splice(to, 0, removedItem);
      return clonedArr;
    }

    var Languages = function Languages(_ref2) {
      var availableLocales = _ref2.availableLocales,
          defaultLocaleId = _ref2.defaultLocaleId,
          _ref2$inheritLocales = _ref2.inheritLocales,
          inheritLocales = _ref2$inheritLocales === void 0 ? true : _ref2$inheritLocales,
          portletNamespace = _ref2.portletNamespace,
          siteAvailableLocales = _ref2.siteAvailableLocales,
          siteDefaultLocaleId = _ref2.siteDefaultLocaleId,
          translatedLanguages = _ref2.translatedLanguages;

      var _useState = (0, _react.useState)(inheritLocales),
          _useState2 = _slicedToArray(_useState, 2),
          currentInheritLocales = _useState2[0],
          setCurrentInheritLocales = _useState2[1];

      var _useState3 = (0, _react.useState)(siteDefaultLocaleId),
          _useState4 = _slicedToArray(_useState3, 2),
          customDefaultLocaleId = _useState4[0],
          setCustomDefaultLocaleId = _useState4[1];

      var _useState5 = (0, _react.useState)(siteAvailableLocales),
          _useState6 = _slicedToArray(_useState5, 2),
          customLocales = _useState6[0],
          setCustomLocales = _useState6[1];

      var _useState7 = (0, _react.useState)(getLocalesInputValue(siteAvailableLocales)),
          _useState8 = _slicedToArray(_useState7, 2),
          localesInputValue = _useState8[0],
          setLocalesInputValue = _useState8[1];

      var _useState9 = (0, _react.useState)(false),
          _useState10 = _slicedToArray(_useState9, 2),
          languageWarning = _useState10[0],
          setLanguageWarning = _useState10[1];

      var _useState11 = (0, _react.useState)(false),
          _useState12 = _slicedToArray(_useState11, 2),
          languageTranslationWarning = _useState12[0],
          setLanguageTranslationWarning = _useState12[1];

      var _useState13 = (0, _react.useState)(false),
          _useState14 = _slicedToArray(_useState13, 2),
          showModal = _useState14[0],
          setShowModal = _useState14[1];

      var _useModal = (0, _modal.useModal)({
        onClose: function handleOnModalClose() {
          setShowModal(false);
        }
      }),
          observer = _useModal.observer,
          onClose = _useModal.onClose;

      var moveItem = function moveItem(currentIndex, newIndex) {
        setCustomLocales(function (languages) {
          return move(languages, currentIndex, newIndex);
        });
      };

      (0, _react.useEffect)(function () {
        if (!currentInheritLocales) {
          setLocalesInputValue(getLocalesInputValue(customLocales));
        }
      }, [customLocales, currentInheritLocales]);
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "mt-5"
        }, /*#__PURE__*/_react.default.createElement(_form.ClayRadioGroup, {
          name: "".concat(portletNamespace, "TypeSettingsProperties--inheritLocales--"),
          onChange: setCurrentInheritLocales,
          value: currentInheritLocales
        }, /*#__PURE__*/_react.default.createElement(_form.ClayRadio, {
          label: Liferay.Language.get('use-the-default-language-options'),
          value: true
        }), /*#__PURE__*/_react.default.createElement(_form.ClayRadio, {
          label: Liferay.Language.get('define-a-custom-default-language-and-additional-active-languages-for-this-asset-library'),
          value: false
        })), currentInheritLocales ? /*#__PURE__*/_react.default.createElement(_LanguagesList.default, {
          defaultLocaleId: defaultLocaleId,
          locales: availableLocales
        }) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", {
          name: "".concat(portletNamespace, "TypeSettingsProperties--languageId--"),
          type: "hidden",
          value: customDefaultLocaleId
        }), /*#__PURE__*/_react.default.createElement("input", {
          name: "".concat(portletNamespace, "TypeSettingsProperties--locales--"),
          type: "hidden",
          value: localesInputValue
        }), /*#__PURE__*/_react.default.createElement(_LanguagesList.default, {
          defaultLocaleId: customDefaultLocaleId,
          isEditable: true,
          locales: customLocales,
          moveItem: moveItem,
          onEditBtnClick: function handleOnModalOpen() {
            setShowModal(true);
          },
          onItemDrop: function handleOnItemDrop(currentIndex, newIndex) {
            moveItem(currentIndex, newIndex);
          },
          onMakeDefault: function handleOnMakeDefault(_ref3) {
            var localeId = _ref3.localeId;
            setCustomDefaultLocaleId(localeId);
            setLanguageWarning(true);
            setLanguageTranslationWarning(translatedLanguages && !translatedLanguages[localeId]);
          }
        })), showModal && /*#__PURE__*/_react.default.createElement(_ManageLanguages.default, {
          availableLocales: availableLocales,
          customDefaultLocaleId: customDefaultLocaleId,
          customLocales: customLocales,
          observer: observer,
          onModalClose: onClose,
          onModalDone: function handleOnModalDone(selectedLocales) {
            setCustomLocales(selectedLocales);
            onClose();
          }
        }), languageWarning && /*#__PURE__*/_react.default.createElement(_alert.default, {
          displayType: "warning",
          onClose: function onClose() {
            return setLanguageWarning(false);
          },
          title: Liferay.Language.get('warning')
        }, Liferay.Language.get('this-change-will-only-affect-the-newly-created-localized-content')), languageTranslationWarning && /*#__PURE__*/_react.default.createElement(_alert.default, {
          displayType: "warning",
          onClose: function onClose() {
            return setLanguageTranslationWarning(false);
          },
          title: Liferay.Language.get('warning')
        }, Liferay.Language.get('asset-library-name-will-display-a-generic-text-until-a-translation-is-added')))
      );
    };

    var _default = Languages;
    exports.default = _default;
    //# sourceMappingURL=Languages.es.js.map
  }
});
//# sourceMappingURL=Languages.es.js.map