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

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

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

    var _highlightedCommentIdKey = require("../../../app/config/constants/highlightedCommentIdKey");

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

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

    var _FragmentComments = _interopRequireDefault(require("./FragmentComments"));

    var _FragmentEntryLinksWithComments = _interopRequireDefault(require("./FragmentEntryLinksWithComments"));

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */
    function getActiveFragmentEntryLink(_ref) {
      var fragmentEntryLinks = _ref.fragmentEntryLinks,
          highlightMessageId = _ref.highlightMessageId,
          itemId = _ref.itemId,
          layoutData = _ref.layoutData;

      if (highlightMessageId) {
        return Object.values(fragmentEntryLinks).find(function (fragmentEntryLink) {
          return fragmentEntryLink.comments.some(function (comment) {
            var _comment$children;

            return comment.commentId === highlightMessageId || ((_comment$children = comment.children) === null || _comment$children === void 0 ? void 0 : _comment$children.some(function (childComment) {
              return childComment.commentId === highlightMessageId;
            }));
          });
        });
      } else {
        var item = layoutData.items[itemId];

        if (item) {
          if (item.type === _layoutDataItemTypes.LAYOUT_DATA_ITEM_TYPES.fragment) {
            return fragmentEntryLinks[item.config.fragmentEntryLinkId];
          } else if (item.parentId) {
            return getActiveFragmentEntryLink({
              fragmentEntryLinks: fragmentEntryLinks,
              itemId: item.parentId,
              layoutData: layoutData
            });
          }
        }
      }

      return null;
    }

    function CommentsSidebar() {
      var fragmentEntryLinks = (0, _index.useSelector)(function (state) {
        return state.fragmentEntryLinks;
      });
      var layoutData = (0, _index.useSelector)(function (state) {
        return state.layoutData;
      });
      var activeItemId = (0, _Controls.useActiveItemId)();
      var selectItem = (0, _Controls.useSelectItem)();
      var highlightMessageId = window.sessionStorage.getItem(_highlightedCommentIdKey.HIGHLIGHTED_COMMENT_ID_KEY);
      var activeFragmentEntryLink = getActiveFragmentEntryLink({
        fragmentEntryLinks: fragmentEntryLinks,
        highlightMessageId: highlightMessageId,
        itemId: activeItemId,
        layoutData: layoutData
      });

      if (highlightMessageId && activeFragmentEntryLink) {
        var activeItem = Object.values(layoutData.items).find(function (item) {
          return item.config.fragmentEntryLinkId === activeFragmentEntryLink.fragmentEntryLinkId;
        });
        selectItem(activeItem.itemId);
      }

      return (/*#__PURE__*/_react.default.createElement("div", {
          onMouseDown: function onMouseDown(event) {
            return event.nativeEvent.stopImmediatePropagation();
          }
        }, activeFragmentEntryLink ? /*#__PURE__*/_react.default.createElement(_FragmentComments.default, {
          fragmentEntryLink: activeFragmentEntryLink
        }) : /*#__PURE__*/_react.default.createElement(_FragmentEntryLinksWithComments.default, null))
      );
    }
    //# sourceMappingURL=CommentsSidebar.js.map
  }
});
//# sourceMappingURL=CommentsSidebar.js.map