Liferay.Loader.define("portal-search-ranking-web@2.0.50/js/components/list/SearchBar.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/management-toolbar', 'frontend-js-react-web$classnames', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', '../../utils/language.es', '../add_result/AddResult.es', './ItemDropdown.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

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

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

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

    var _managementToolbar = _interopRequireDefault(require("@frontend-taglib-clay$clayui/management-toolbar"));

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

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

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

    var _language = require("../../utils/language.es");

    var _AddResult = _interopRequireDefault(require("../add_result/AddResult.es"));

    var _ItemDropdown = _interopRequireDefault(require("./ItemDropdown.es"));

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

    function _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }

    function _defineProperties(target, props) {
      for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
      }
    }

    function _createClass(Constructor, protoProps, staticProps) {
      if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);return Constructor;
    }

    function _possibleConstructorReturn(self, call) {
      if (call && (_typeof(call) === "object" || typeof call === "function")) {
        return call;
      }return _assertThisInitialized(self);
    }

    function _getPrototypeOf(o) {
      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
      };return _getPrototypeOf(o);
    }

    function _assertThisInitialized(self) {
      if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }return self;
    }

    function _inherits(subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
      }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });if (superClass) _setPrototypeOf(subClass, superClass);
    }

    function _setPrototypeOf(o, p) {
      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
        o.__proto__ = p;return o;
      };return _setPrototypeOf(o, p);
    }

    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 SearchBar = /*#__PURE__*/function (_Component) {
      _inherits(SearchBar, _Component);

      function SearchBar() {
        var _getPrototypeOf2;

        var _this;

        _classCallCheck(this, SearchBar);

        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(SearchBar)).call.apply(_getPrototypeOf2, [this].concat(args)));

        _defineProperty(_assertThisInitialized(_this), "_handleAllCheckbox", function () {
          if (_this.props.selectedIds.length > 0) {
            _this.props.onSelectClear();
          } else {
            _this.props.onSelectAll();
          }
        });

        _defineProperty(_assertThisInitialized(_this), "_handleClickHide", function () {
          var _this$props = _this.props,
              onClickHide = _this$props.onClickHide,
              onRemoveSelect = _this$props.onRemoveSelect,
              selectedIds = _this$props.selectedIds;
          onRemoveSelect(selectedIds);
          onClickHide(selectedIds, !_this._isAnyHidden());
        });

        _defineProperty(_assertThisInitialized(_this), "_handleClickPin", function () {
          var _this$props2 = _this.props,
              dataMap = _this$props2.dataMap,
              onClickPin = _this$props2.onClickPin,
              onRemoveSelect = _this$props2.onRemoveSelect,
              selectedIds = _this$props2.selectedIds;
          var unpinnedIds = selectedIds.filter(function (id) {
            return !dataMap[id].pinned;
          });

          if (unpinnedIds.length) {
            onRemoveSelect(selectedIds.filter(function (id) {
              return dataMap[id].hidden;
            }));
            onClickPin(unpinnedIds, true);
          } else {
            onRemoveSelect(selectedIds.filter(function (id) {
              return dataMap[id].addedResult;
            }));
            onClickPin(selectedIds, false);
          }
        });

        _defineProperty(_assertThisInitialized(_this), "_hasSelectedIds", function () {
          return _this.props.selectedIds.length > 0;
        });

        _defineProperty(_assertThisInitialized(_this), "_isAnyHidden", function () {
          var _this$props3 = _this.props,
              dataMap = _this$props3.dataMap,
              selectedIds = _this$props3.selectedIds;
          return selectedIds.some(function (id) {
            return dataMap[id].hidden;
          });
        });

        _defineProperty(_assertThisInitialized(_this), "_isAnyUnpinned", function () {
          var _this$props4 = _this.props,
              dataMap = _this$props4.dataMap,
              selectedIds = _this$props4.selectedIds;
          return selectedIds.some(function (id) {
            return !dataMap[id].pinned;
          });
        });

        return _this;
      }

      _createClass(SearchBar, [{
        key: "render",
        value: function render() {
          var _this$props5 = this.props,
              fetchDocumentsSearchUrl = _this$props5.fetchDocumentsSearchUrl,
              onAddResultSubmit = _this$props5.onAddResultSubmit,
              resultIds = _this$props5.resultIds,
              selectedIds = _this$props5.selectedIds;
          var classManagementBar = (0, _classnames.default)(this._hasSelectedIds() ? 'management-bar-primary' : 'management-bar-light');
          var classNavBarForm = (0, _classnames.default)('navbar-form', 'navbar-form-autofit', 'navbar-overlay');
          return (/*#__PURE__*/_react.default.createElement("div", {
              className: "search-bar-root"
            }, /*#__PURE__*/_react.default.createElement(_managementToolbar.default, {
              className: classManagementBar
            }, /*#__PURE__*/_react.default.createElement("div", {
              className: classNavBarForm
            }, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.ItemList, null, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement(_form.ClayCheckbox, {
              "aria-label": Liferay.Language.get('select-all'),
              checked: this._hasSelectedIds(),
              disabled: !resultIds.length,
              indeterminate: selectedIds.length > 0 && selectedIds.length !== resultIds.length,
              onChange: this._handleAllCheckbox
            }))), this._hasSelectedIds() && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.ItemList, {
              expand: true
            }, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement("span", {
              className: "navbar-text"
            }, (0, _language.getPluralMessage)(Liferay.Language.get('x-item-selected'), Liferay.Language.get('x-items-selected'), selectedIds.length)))), /*#__PURE__*/_react.default.createElement(_managementToolbar.default.ItemList, null, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement("div", {
              className: "nav-link nav-link-monospaced"
            }, /*#__PURE__*/_react.default.createElement(_button.default, {
              className: "btn-outline-borderless component-action",
              displayType: "secondary",
              onClick: this._handleClickHide,
              title: this._isAnyHidden() ? Liferay.Language.get('show-result') : Liferay.Language.get('hide-result')
            }, /*#__PURE__*/_react.default.createElement(_icon.default, {
              symbol: this._isAnyHidden() ? 'view' : 'hidden'
            })))), /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement("div", {
              className: "nav-link nav-link-monospaced"
            }, /*#__PURE__*/_react.default.createElement(_button.default, {
              className: "btn-outline-borderless component-action",
              displayType: "secondary",
              onClick: this._handleClickPin,
              title: this._isAnyUnpinned() ? Liferay.Language.get('pin-result') : Liferay.Language.get('unpin-result')
            }, this._isAnyUnpinned() ? /*#__PURE__*/_react.default.createElement(_icon.default, {
              key: "PIN",
              symbol: "pin"
            }) : /*#__PURE__*/_react.default.createElement(_icon.default, {
              key: "UNPIN",
              symbol: "unpin"
            })))), /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement("div", {
              className: "nav-link nav-link-monospaced"
            }, /*#__PURE__*/_react.default.createElement(_ItemDropdown.default, {
              hidden: this._isAnyHidden(),
              itemCount: selectedIds.length,
              onClickHide: this._handleClickHide,
              onClickPin: this._handleClickPin,
              pinned: !this._isAnyUnpinned()
            }))))), !this._hasSelectedIds() && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.ItemList, {
              expand: true
            }, !!resultIds.length && /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement("span", {
              className: "component-text navbar-text"
            }, Liferay.Language.get('select-items')))), onAddResultSubmit && /*#__PURE__*/_react.default.createElement(_managementToolbar.default.ItemList, null, /*#__PURE__*/_react.default.createElement(_managementToolbar.default.Item, null, /*#__PURE__*/_react.default.createElement(_AddResult.default, {
              fetchDocumentsSearchUrl: fetchDocumentsSearchUrl,
              onAddResultSubmit: onAddResultSubmit
            })))))))
          );
        }
      }]);

      return SearchBar;
    }(_react.Component);

    _defineProperty(SearchBar, "defaultProps", {
      resultIds: [],
      selectedIds: []
    });

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