Liferay.Loader.define("commerce-frontend-js@3.0.33/components/dataset_display/management_bar/components/FiltersDropdown", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/drop-down', '@frontend-taglib-clay$clayui/icon', 'frontend-js-react-web$react', './Context', './filters/index'], 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 = require("@frontend-taglib-clay$clayui/button");

    var _dropDown = _interopRequireDefault(require("@frontend-taglib-clay$clayui/drop-down"));

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

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

    var _Context = _interopRequireDefault(require("./Context"));

    var _index = require("./filters/index");

    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 _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 FiltersDropdown() {
      var _useState = (0, _react.useState)(false),
          _useState2 = _slicedToArray(_useState, 2),
          active = _useState2[0],
          setActive = _useState2[1];

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

      var _getAppContext = (0, _Context.default)(),
          state = _getAppContext.state;

      var _useState5 = (0, _react.useState)(state.filters.filter(function (filter) {
        return !filter.invisible;
      })),
          _useState6 = _slicedToArray(_useState5, 2),
          visibleFilters = _useState6[0],
          setVisibleFilter = _useState6[1];

      var _useState7 = (0, _react.useState)(null),
          _useState8 = _slicedToArray(_useState7, 2),
          activeFilterId = _useState8[0],
          setActiveFilterId = _useState8[1];

      var activeFilter = (0, _react.useMemo)(function () {
        return activeFilterId && visibleFilters.find(function (filter) {
          return filter.id === activeFilterId;
        });
      }, [visibleFilters, activeFilterId]);

      var _getAppContext2 = (0, _Context.default)(),
          actions = _getAppContext2.actions;

      (0, _react.useEffect)(function () {
        var results = state.filters.filter(function (filter) {
          switch (true) {
            case !!filter.invisible:
              return false;

            case query && !(filter.id.toLowerCase().includes(query) || filter.label.toLowerCase().includes(query)):
              return false;

            default:
              return true;
          }
        });
        setVisibleFilter(results);
      }, [state.filters, query]);
      return state.filters.length ? /*#__PURE__*/_react.default.createElement(_dropDown.default, {
        active: active,
        className: "filters-dropdown",
        onActiveChange: setActive,
        trigger: /*#__PURE__*/_react.default.createElement("button", {
          className: "btn btn-unstyled dropdown-toggle filters-dropdown-button",
          type: "button"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "navbar-text-truncate"
        }, Liferay.Language.get('filter')), active ? /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: "ml-2",
          symbol: "caret-top"
        }) : /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: "ml-2",
          symbol: "caret-bottom"
        }))
      }, activeFilterId ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("li", {
        className: "dropdown-subheader"
      }, /*#__PURE__*/_react.default.createElement(_button.ClayButtonWithIcon, {
        className: "btn-filter-navigation",
        displayType: "unstyled",
        onClick: function onClick() {
          return setActiveFilterId(null);
        },
        small: true,
        symbol: "angle-left"
      }), activeFilter.label), /*#__PURE__*/_react.default.createElement(_index.Filter, _objectSpread(_objectSpread({}, activeFilter), {}, {
        actions: actions
      }))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("li", {
        className: "dropdown-subheader"
      }, Liferay.Language.get('filters')), /*#__PURE__*/_react.default.createElement(_dropDown.default.Search, {
        onChange: function onChange(e) {
          return setQuery(e.target.value);
        },
        value: query
      }), /*#__PURE__*/_react.default.createElement(_dropDown.default.Divider, {
        className: "m-0"
      }), visibleFilters.length ? /*#__PURE__*/_react.default.createElement(_dropDown.default.ItemList, null, visibleFilters.map(function (item) {
        return (/*#__PURE__*/_react.default.createElement(_dropDown.default.Item, {
            active: item.value !== undefined && item.value !== null,
            key: item.id,
            onClick: function onClick() {
              return setActiveFilterId(item.id);
            }
          }, item.label)
        );
      })) : /*#__PURE__*/_react.default.createElement("div", {
        className: "dropdown-section text-muted"
      }, Liferay.Language.get('no-filters-were-found')))) : null;
    }

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