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

var _chunk6UOQP5QHjs = require('./chunk-6UOQP5QH.js');


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


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


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

// tmp-babel/comments/web/CommentItem/CommentsReplies/index.js
var _react = require('react');
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);
}
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var CommentsReplies = function CommentsReplies2(_ref) {
  var _target$comments2;
  var targetRef = _ref.target, currentThreadDepth = _ref.currentThreadDepth, subscriptionsEnabled = _ref.subscriptionsEnabled, onReplyClick = _ref.onReplyClick, CommentItem = _ref.CommentItem, VirtuosoProps = _ref.VirtuosoProps;
  var _useCommentList = _chunkM3BOYEO4js.useCommentList.call(void 0, targetRef), target = _useCommentList.data, loadNext = _useCommentList.loadNext, isLoadingNext = _useCommentList.isLoadingNext, hasNext = _useCommentList.hasNext;
  var _useTransition = _react.useTransition.call(void 0, ), _useTransition2 = _slicedToArray(_useTransition, 2), isPending = _useTransition2[0], startTransition = _useTransition2[1];
  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, {
      target,
      comment,
      currentThreadDepth,
      subscriptionsEnabled,
      onReplyClick
    }, "comment-reply-".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 renderLoadingMoreButton = function renderLoadingMoreButton2() {
    var _target$commentsCount;
    if (!hasNext) return null;
    var commentsLeft = Number(target === null || target === void 0 || (_target$commentsCount = target.commentsCount) === null || _target$commentsCount === void 0 ? void 0 : _target$commentsCount.total) - comments.length;
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      sx: {
        paddingTop: 1
      },
      children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunk6UOQP5QHjs.LoadMoreRepliesButton, {
        variant: "text",
        size: "small",
        disableElevation: true,
        disableRipple: true,
        disabled: isPending || isLoadingNext,
        onClick: function onClick() {
          startTransition(function() {
            loadNext(_chunkNSWGZREEjs.NUMBER_OF_COMMENTS_TO_LOAD_NEXT);
          });
        },
        children: ["Show more replies (", commentsLeft, ")"]
      })
    });
  };
  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, _reactvirtuoso.Virtuoso, _objectSpread({
      useWindowScroll: true,
      data: comments,
      itemContent: function itemContent(_index, comment) {
        return renderCommentItem(comment);
      },
      components: {
        Header: renderHeader,
        Footer: renderLoadingMoreButton
      }
    }, VirtuosoProps))]
  });
};
var CommentsReplies_default = CommentsReplies;



exports.CommentsReplies_default = CommentsReplies_default;
//# sourceMappingURL=chunk-Y7ZIW6UQ.js.map