var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/comment/list/list-item/index.tsx
var list_item_exports = {};
__export(list_item_exports, {
  default: () => list_item_default
});
module.exports = __toCommonJS(list_item_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_ahooks = require("ahooks");
var import_moment = __toESM(require("moment"));
var import_context = require("../../../config-provider/context");
var import_utils = require("../../../locale/utils");
var import_comment_detail = __toESM(require("../comment-detail"));
var import_service = require("../../service");
var import_index = require("./index.less");
var maxCount = 3;
var CommentListItemMinor = (props) => {
  const { uiLocale } = (0, import_react.useContext)(import_context.ConfigContext);
  const { commentId, total, items, onLoadMoreReply, getToken, ...rest } = props;
  const [list, setList] = (0, import_react.useState)([]);
  const { loading, runAsync } = (0, import_ahooks.useRequest)(import_service.getCommentReplyList, { manual: true });
  const isFirst = (0, import_react.useRef)(true);
  const onLoadMore = () => {
    if (isFirst.current) {
      setList(items);
      isFirst.current = false;
      return;
    }
    getToken().then((data) => {
      runAsync({
        orderId: (0, import_moment.default)(list[list.length - 1].id).valueOf(),
        page: 1,
        pageSize: 10,
        id: commentId,
        accessToken: data == null ? void 0 : data.accessToken
      }).then((res) => {
        res.items && onLoadMoreReply(commentId, res.items);
      });
    });
  };
  (0, import_react.useEffect)(() => {
    if (isFirst.current) {
      setList([...items].splice(0, maxCount));
      return;
    }
    setList(items);
  }, [items]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "u-comment-item-minor" }, list.map((item) => /* @__PURE__ */ import_react.default.createElement("div", { className: "minor-item", key: item.id }, /* @__PURE__ */ import_react.default.createElement(
    import_comment_detail.default,
    {
      ...rest,
      className: "minor-comment",
      type: "minor",
      record: item,
      commentId,
      parentReplyId: item.id,
      getToken
    }
  ))), total > maxCount && list.length < total && /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-load-more" }, /* @__PURE__ */ import_react.default.createElement("span", null, (0, import_utils.replaceMessage)(uiLocale.Comment.totalComment, { count: total })), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "link", onClick: onLoadMore, loading }, uiLocale.Comment.loadMore)));
};
var CommentListItem = (props) => {
  var _a;
  const { record, renderAvatar, ...rest } = props;
  const _renderAvatar = () => {
    const commentor = record.commentor;
    return renderAvatar ? renderAvatar(commentor ? { id: commentor.id, name: commentor.name, other: JSON.parse(commentor.other || "{}") } : null) : /* @__PURE__ */ import_react.default.createElement(import_antd.Avatar, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.UserOutlined, null) });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "u-comment-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-avatar" }, _renderAvatar()), /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-wrap" }, /* @__PURE__ */ import_react.default.createElement(import_comment_detail.default, { ...rest, record, type: "main", commentId: record.id }), !!((_a = record.replyDTOPageInfo) == null ? void 0 : _a.total) && /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-expend" }, /* @__PURE__ */ import_react.default.createElement(
    CommentListItemMinor,
    {
      ...rest,
      commentId: record.id,
      total: record.replyDTOPageInfo.total,
      items: record.replyDTOPageInfo.items
    }
  ))));
};
var list_item_default = CommentListItem;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
