Liferay.Loader.define("asset-list-web@2.0.99/auto_field/index", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', 'asset-taglib', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react'], 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 _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

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

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

    var _assetTaglib = require("asset-taglib");

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

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

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

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

    var DEFAULT_RULE = {
      queryContains: true,
      type: 'assetTags'
    };
    var QUERY_AND_OPERATOR_OPTIONS = [{
      label: Liferay.Language.get('all'),
      value: true
    }, {
      label: Liferay.Language.get('any'),
      value: false
    }];
    var QUERY_CONTAINS_OPTIONS = [{
      label: Liferay.Language.get('contains'),
      value: true
    }, {
      label: Liferay.Language.get('does-not-contain'),
      value: false
    }];
    var RULE_TYPE_OPTIONS = [{
      label: Liferay.Language.get('categories'),
      value: 'assetCategories'
    }, {
      label: Liferay.Language.get('keywords'),
      value: 'keywords'
    }, {
      label: Liferay.Language.get('tags'),
      value: 'assetTags'
    }];

    function AssetCategories(_ref) {
      var categorySelectorURL = _ref.categorySelectorURL,
          groupIds = _ref.groupIds,
          index = _ref.index,
          namespace = _ref.namespace,
          rule = _ref.rule,
          vocabularyIds = _ref.vocabularyIds;

      var _useState = (0, _react.useState)(rule.selectedItems || []),
          _useState2 = _slicedToArray(_useState, 2),
          selectedItems = _useState2[0],
          setSelectedItems = _useState2[1];

      return (/*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement("label", {
          htmlFor: "".concat(namespace, "queryCategoryIds").concat(index)
        }, Liferay.Language.get('categories')), /*#__PURE__*/_react.default.createElement(_assetTaglib.AssetVocabularyCategoriesSelector, {
          categoryIds: rule.queryValues ? rule.queryValues : '',
          eventName: "".concat(namespace, "selectCategory"),
          groupIds: groupIds,
          inputName: "".concat(namespace, "queryCategoryIds").concat(index),
          onSelectedItemsChange: setSelectedItems,
          portletURL: categorySelectorURL,
          selectedItems: selectedItems,
          sourceItemsVocabularyIds: vocabularyIds
        }))
      );
    }

    function AssetTags(_ref2) {
      var groupIds = _ref2.groupIds,
          index = _ref2.index,
          namespace = _ref2.namespace,
          rule = _ref2.rule,
          tagSelectorURL = _ref2.tagSelectorURL;

      var _useState3 = (0, _react.useState)(''),
          _useState4 = _slicedToArray(_useState3, 2),
          inputValue = _useState4[0],
          setInputValue = _useState4[1];

      var _useState5 = (0, _react.useState)(rule.selectedItems),
          _useState6 = _slicedToArray(_useState5, 2),
          selectedItems = _useState6[0],
          setSelectedItems = _useState6[1];

      return (/*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement(_assetTaglib.AssetTagsSelector, {
          eventName: "".concat(namespace, "selectTag"),
          groupIds: groupIds,
          inputName: "".concat(namespace, "queryTagNames").concat(index),
          inputValue: inputValue,
          onInputValueChange: setInputValue,
          onSelectedItemsChange: setSelectedItems,
          portletURL: tagSelectorURL,
          selectedItems: selectedItems,
          showSelectButton: true,
          tagNames: rule.queryValues ? rule.queryValues : ''
        }))
      );
    }

    function Keywords(_ref3) {
      var index = _ref3.index,
          namespace = _ref3.namespace,
          onChange = _ref3.onChange,
          rule = _ref3.rule;
      return (/*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement("label", {
          htmlFor: "".concat(namespace, "keywords").concat(index)
        }, Liferay.Language.get('keywords')), /*#__PURE__*/_react.default.createElement(_form.ClayInput, {
          className: "asset-query-keywords",
          "data-index": index,
          "data-item-index": index,
          "data-property": "queryValues",
          id: "".concat(namespace, "keywords").concat(index),
          name: "".concat(namespace, "keywords").concat(index),
          onChange: onChange,
          type: "text",
          value: rule.queryValues
        }))
      );
    }

    function Rule(_ref4) {
      var categorySelectorURL = _ref4.categorySelectorURL,
          disabled = _ref4.disabled,
          groupIds = _ref4.groupIds,
          index = _ref4.index,
          namespace = _ref4.namespace,
          onDeleteRule = _ref4.onDeleteRule,
          onRuleChange = _ref4.onRuleChange,
          rule = _ref4.rule,
          tagSelectorURL = _ref4.tagSelectorURL,
          vocabularyIds = _ref4.vocabularyIds;
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
          className: "panel panel-default"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "panel-body"
        }, /*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement(_form.ClaySelectWithOption, {
          "data-index": index,
          "data-property": "queryContains",
          id: "".concat(namespace, "queryContains").concat(index),
          name: "".concat(namespace, "queryContains").concat(index),
          onChange: onRuleChange,
          options: QUERY_CONTAINS_OPTIONS,
          title: Liferay.Language.get('query-contains'),
          value: rule.queryContains
        })), /*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement(_form.ClaySelectWithOption, {
          "data-index": index,
          "data-property": "queryAndOperator",
          id: "".concat(namespace, "queryAndOperator").concat(index),
          name: "".concat(namespace, "queryAndOperator").concat(index),
          onChange: onRuleChange,
          options: QUERY_AND_OPERATOR_OPTIONS,
          title: Liferay.Language.get('and-operator'),
          value: rule.queryAndOperator
        })), /*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement("label", {
          className: "control-label",
          htmlFor: "".concat(namespace, "queryName").concat(index)
        }, Liferay.Language.get('of-the-following'))), /*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement(_form.ClaySelectWithOption, {
          "data-index": index,
          "data-property": "type",
          id: "".concat(namespace, "queryName").concat(index),
          name: "".concat(namespace, "queryName").concat(index),
          onChange: onRuleChange,
          options: RULE_TYPE_OPTIONS,
          value: rule.type
        })), rule.type === 'assetCategories' && /*#__PURE__*/_react.default.createElement(AssetCategories, {
          categorySelectorURL: categorySelectorURL,
          groupIds: groupIds,
          index: index,
          namespace: namespace,
          rule: rule,
          vocabularyIds: vocabularyIds
        }), rule.type === 'assetTags' && /*#__PURE__*/_react.default.createElement(AssetTags, {
          groupIds: groupIds,
          index: index,
          namespace: namespace,
          rule: rule,
          tagSelectorURL: tagSelectorURL
        }), rule.type === 'keywords' && /*#__PURE__*/_react.default.createElement(Keywords, {
          index: index,
          namespace: namespace,
          onChange: onRuleChange,
          rule: rule
        }), /*#__PURE__*/_react.default.createElement("div", {
          className: "timeline-increment"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "timeline-icon"
        })))), !disabled && /*#__PURE__*/_react.default.createElement("div", {
          className: "container-trash"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "condition-card-delete",
          "data-index": index,
          monospaced: true,
          onClick: onDeleteRule,
          small: true
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "trash"
        }))))
      );
    }

    function AutoField(_ref5) {
      var categorySelectorURL = _ref5.categorySelectorURL,
          disabled = _ref5.disabled,
          groupIds = _ref5.groupIds,
          namespace = _ref5.namespace,
          rules = _ref5.rules,
          tagSelectorURL = _ref5.tagSelectorURL,
          vocabularyIds = _ref5.vocabularyIds;

      var _useState7 = (0, _react.useState)(rules),
          _useState8 = _slicedToArray(_useState7, 2),
          currentRules = _useState8[0],
          setCurrentRules = _useState8[1];

      var handleAddRule = (0, _react.useCallback)(function () {
        setCurrentRules([].concat(_toConsumableArray(currentRules), [DEFAULT_RULE]));
      }, [currentRules]);
      var handleDeleteRule = (0, _react.useCallback)(function (event) {
        var index = parseInt(event.currentTarget.dataset.index, 10);
        setCurrentRules([].concat(_toConsumableArray(currentRules.slice(0, index)), _toConsumableArray(currentRules.slice(index + 1, currentRules.length))));
      }, [currentRules]);
      var handleRuleChange = (0, _react.useCallback)(function (event) {
        var index = parseInt(event.currentTarget.dataset.index, 10);
        var property = event.currentTarget.dataset.property;
        var rule = property === 'type' ? {
          queryContains: true
        } : currentRules[index];
        setCurrentRules([].concat(_toConsumableArray(currentRules.slice(0, index)), [_objectSpread(_objectSpread({}, rule), {}, _defineProperty({}, property, event.currentTarget.value))], _toConsumableArray(currentRules.slice(index + 1, currentRules.length))));
      }, [currentRules]);
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_form.ClayInput, {
          name: "".concat(namespace, "queryLogicIndexes"),
          type: "hidden",
          value: Object.keys(currentRules).toString()
        }), /*#__PURE__*/_react.default.createElement("ul", {
          className: "timeline"
        }, /*#__PURE__*/_react.default.createElement("li", {
          className: "timeline-item"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "flex-container panel-body"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "timeline-increment"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "timeline-icon"
        })))), currentRules.map(function (rule, index) {
          return (/*#__PURE__*/_react.default.createElement("li", {
              className: "timeline-item",
              key: index
            }, /*#__PURE__*/_react.default.createElement(Rule, {
              categorySelectorURL: categorySelectorURL,
              disabled: disabled,
              groupIds: groupIds,
              index: index,
              namespace: namespace,
              onDeleteRule: handleDeleteRule,
              onRuleChange: handleRuleChange,
              rule: rule,
              tagSelectorURL: tagSelectorURL,
              vocabularyIds: vocabularyIds
            }))
          );
        })), !disabled && /*#__PURE__*/_react.default.createElement("div", {
          className: "addbutton-timeline-item"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "add-condition timeline-increment-icon"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "form-builder-rule-add-condition form-builder-timeline-add-item",
          monospaced: true,
          onClick: handleAddRule,
          small: true
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "plus"
        })))))
      );
    }

    var _default = AutoField;
    exports.default = _default;
    //# sourceMappingURL=index.js.map
  }
});
//# sourceMappingURL=index.js.map