Liferay.Loader.define("layout-content-page-editor-web@2.0.161/page_editor/plugins/comments/components/FragmentEntryLinksWithComments", ['module', 'exports', 'require', 'frontend-js-react-web$react', '../../../app/components/Controls', '../../../app/config/constants/layoutDataItemTypes', '../../../app/store/index', '../../../common/components/SidebarPanelContent', '../../../common/components/SidebarPanelHeader', './NoCommentsMessage', './ResolvedCommentsToggle'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = FragmentEntryLinksWithComments;

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

    var _Controls = require("../../../app/components/Controls");

    var _layoutDataItemTypes = require("../../../app/config/constants/layoutDataItemTypes");

    var _index = require("../../../app/store/index");

    var _SidebarPanelContent = _interopRequireDefault(require("../../../common/components/SidebarPanelContent"));

    var _SidebarPanelHeader = _interopRequireDefault(require("../../../common/components/SidebarPanelHeader"));

    var _NoCommentsMessage = _interopRequireDefault(require("./NoCommentsMessage"));

    var _ResolvedCommentsToggle = _interopRequireDefault(require("./ResolvedCommentsToggle"));

    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 FragmentEntryLinksWithComments() {
      var itemsWithComments = (0, _index.useSelector)(function (state) {
        return Object.values(state.layoutData.items).filter(function (item) {
          return item.type === _layoutDataItemTypes.LAYOUT_DATA_ITEM_TYPES.fragment;
        }).map(function (item) {
          return [item, state.fragmentEntryLinks[item.config.fragmentEntryLinkId]];
        }).map(function (_ref) {
          var _ref2 = _slicedToArray(_ref, 2),
              item = _ref2[0],
              fragmentEntryLink = _ref2[1];

          return [item, _objectSpread(_objectSpread({}, fragmentEntryLink), {}, {
            comments: (fragmentEntryLink.comments || []).filter(function (_ref3) {
              var resolved = _ref3.resolved;
              return state.showResolvedComments && resolved || !resolved;
            })
          })];
        }).filter(function (_ref4) {
          var _ref5 = _slicedToArray(_ref4, 2),
              fragmentEntryLink = _ref5[1];

          return fragmentEntryLink.comments.length;
        });
      });
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_SidebarPanelHeader.default, null, Liferay.Language.get('comments')), /*#__PURE__*/_react.default.createElement(_SidebarPanelContent.default, {
          padded: false
        }, /*#__PURE__*/_react.default.createElement(_ResolvedCommentsToggle.default, null), itemsWithComments.length ? /*#__PURE__*/_react.default.createElement("nav", {
          className: "list-group"
        }, itemsWithComments.map(function (_ref6) {
          var _ref7 = _slicedToArray(_ref6, 2),
              item = _ref7[0],
              fragmentEntryLink = _ref7[1];

          return (/*#__PURE__*/_react.default.createElement(FragmentEntryLinkWithComments, {
              fragmentEntryLink: fragmentEntryLink,
              item: item,
              key: fragmentEntryLink.fragmentEntryLinkId
            })
          );
        })) : /*#__PURE__*/_react.default.createElement(_NoCommentsMessage.default, null)))
      );
    }

    function FragmentEntryLinkWithComments(_ref8) {
      var fragmentEntryLink = _ref8.fragmentEntryLink,
          item = _ref8.item;
      var selectItem = (0, _Controls.useSelectItem)();
      var hoverItem = (0, _Controls.useHoverItem)();
      return (/*#__PURE__*/_react.default.createElement("button", {
          "aria-label": Liferay.Language.get('show-comments'),
          className: "border-0 list-group-item list-group-item-action",
          onClick: function onClick() {
            return selectItem(item.itemId);
          },
          onFocus: function onFocus() {
            return hoverItem(item.itemId);
          },
          onMouseOut: function onMouseOut() {
            return hoverItem(null);
          },
          onMouseOver: function onMouseOver() {
            return hoverItem(item.itemId);
          },
          type: "button"
        }, /*#__PURE__*/_react.default.createElement("strong", {
          className: "d-block text-dark"
        }, fragmentEntryLink.name), /*#__PURE__*/_react.default.createElement("span", {
          className: "text-secondary"
        }, Liferay.Util.sub(fragmentEntryLink.comments.length === 1 ? Liferay.Language.get('x-comment') : Liferay.Language.get('x-comments'), fragmentEntryLink.comments.length)))
      );
    }
    //# sourceMappingURL=FragmentEntryLinksWithComments.js.map
  }
});
//# sourceMappingURL=FragmentEntryLinksWithComments.js.map