"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkSPSXLSARjs = require('./chunk-SPSXLSAR.js');


var _chunkM3BOYEO4js = require('./chunk-M3BOYEO4.js');


var _chunkUH7THWL3js = require('./chunk-UH7THWL3.js');


var _chunkNSWGZREEjs = require('./chunk-NSWGZREE.js');

// tmp-babel/comments/web/CommentsList/index.js
var _react = require('react');
var _displays = require('@baseapp-frontend/design-system/components/web/displays');
var _material = require('@mui/material');
var _reactvirtuoso = require('react-virtuoso');
var _jsxruntime = require('react/jsx-runtime');
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
var CommentsList = function CommentsList2(_ref) {
  var _target$comments2;
  var targetRef = _ref.target, subscriptionsEnabled = _ref.subscriptionsEnabled, onReplyClick = _ref.onReplyClick, _ref$CommentItem = _ref.CommentItem, CommentItem = _ref$CommentItem === void 0 ? _chunkSPSXLSARjs.CommentItem_default : _ref$CommentItem, CommentItemProps = _ref.CommentItemProps, VirtuosoProps = _ref.VirtuosoProps;
  var _useCommentList = _chunkM3BOYEO4js.useCommentList.call(void 0, targetRef), target = _useCommentList.data, loadNext = _useCommentList.loadNext, isLoadingNext = _useCommentList.isLoadingNext, hasNext = _useCommentList.hasNext;
  var comments = _react.useMemo.call(void 0, function() {
    var _target$comments;
    return (target === null || target === void 0 || (_target$comments = target.comments) === null || _target$comments === void 0 ? void 0 : _target$comments.edges.filter(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    }).map(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    })) || [];
  }, [target === null || target === void 0 || (_target$comments2 = target.comments) === null || _target$comments2 === void 0 ? void 0 : _target$comments2.edges]);
  var renderCommentItem = function renderCommentItem2(comment) {
    if (!comment) return null;
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CommentItem, _objectSpread({
      target,
      comment,
      currentThreadDepth: 1,
      subscriptionsEnabled,
      onReplyClick,
      enableDelete: true
    }, CommentItemProps), "comment-".concat(comment.id));
  };
  var renderHeader = function renderHeader2() {
    if (comments.length === 0) return null;
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
      className: "h-2"
    });
  };
  var renderLoadingState = function renderLoadingState2() {
    if (!isLoadingNext) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      sx: {
        paddingTop: 3
      }
    });
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _displays.LoadingState, {
      sx: {
        paddingTop: 3,
        paddingBottom: 1
      },
      CircularProgressProps: {
        size: 15
      },
      "aria-label": "loading more comments"
    });
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
    children: [subscriptionsEnabled && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUH7THWL3js.CommentsSubscription, {
      targetObjectId: target.id
    }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
      className: "overflow-x-auto hide-scrollbar",
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactvirtuoso.Virtuoso, _objectSpread({
        useWindowScroll: true,
        data: comments,
        itemContent: function itemContent(_index, comment) {
          return renderCommentItem(comment);
        },
        components: {
          Header: renderHeader,
          Footer: renderLoadingState
        },
        endReached: function endReached() {
          if (hasNext) {
            loadNext(_chunkNSWGZREEjs.NUMBER_OF_COMMENTS_TO_LOAD_NEXT);
          }
        }
      }, VirtuosoProps))
    })]
  });
};
var CommentsList_default = CommentsList;



exports.CommentsList_default = CommentsList_default;
//# sourceMappingURL=chunk-TVIJNNPG.js.map