"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkY7ZIW6UQjs = require('./chunk-Y7ZIW6UQ.js');


var _chunkYU7MWHBQjs = require('./chunk-YU7MWHBQ.js');


var _chunkBZ5TEGFDjs = require('./chunk-BZ5TEGFD.js');


var _chunkPXTVW3TOjs = require('./chunk-PXTVW3TO.js');


var _chunkGWDR7EGNjs = require('./chunk-GWDR7EGN.js');


var _chunkB23JN7UHjs = require('./chunk-B23JN7UH.js');



var _chunkHEJJ6AAFjs = require('./chunk-HEJJ6AAF.js');


var _chunkIRF4AGBWjs = require('./chunk-IRF4AGBW.js');


var _chunkBWGH36W2js = require('./chunk-BWGH36W2.js');


var _chunkNMH52K53js = require('./chunk-NMH52K53.js');


var _chunkGLOZC7GOjs = require('./chunk-GLOZC7GO.js');


var _chunkIFVB5H42js = require('./chunk-IFVB5H42.js');

// tmp-babel/comments/web/CommentItem/index.js
var _react = require('react');
var _avatars = require('@baseapp-frontend/design-system/components/web/avatars');
var _material = require('@mui/material');
var _link = require('next/link'); var _link2 = _interopRequireDefault(_link);
var _navigation = require('next/navigation');
var _reactrelay = require('react-relay');
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);
}
var _excluded = ["actions"];
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 _objectWithoutProperties(e, t) {
  if (null == e) return {};
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  }
  return i;
}
function _objectWithoutPropertiesLoose(r, e) {
  if (null == r) return {};
  var t = {};
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
    if (-1 !== e.indexOf(n)) continue;
    t[n] = r[n];
  }
  return 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 _CommentItem = function CommentItem(_ref) {
  var _comment$user, _comment$user$fullNam, _comment$user3, _comment$user4, _comment$user5;
  var commentRef = _ref.comment, currentThreadDepth = _ref.currentThreadDepth, subscriptionsEnabled = _ref.subscriptionsEnabled, onReplyClick = _ref.onReplyClick, CommentUpdateProps = _ref.CommentUpdateProps, CommentsRepliesProps = _ref.CommentsRepliesProps, ActionOverlayProps = _ref.ActionOverlayProps, _ref$enableDelete = _ref.enableDelete, enableDelete = _ref$enableDelete === void 0 ? false : _ref$enableDelete, _ref$Timestamp = _ref.Timestamp, Timestamp = _ref$Timestamp === void 0 ? _chunkGLOZC7GOjs.Timestamp_default : _ref$Timestamp, _ref$CommentUpdate = _ref.CommentUpdate, CommentUpdate = _ref$CommentUpdate === void 0 ? _chunkB23JN7UHjs.CommentUpdate_default : _ref$CommentUpdate, _ref$CommentReplyButt = _ref.CommentReplyButton, CommentReplyButton = _ref$CommentReplyButt === void 0 ? _chunkGWDR7EGNjs.CommentReplyButton_default : _ref$CommentReplyButt, _ref$CommentPinnedBad = _ref.CommentPinnedBadge, CommentPinnedBadge = _ref$CommentPinnedBad === void 0 ? _chunkBZ5TEGFDjs.CommentPinnedBadge_default : _ref$CommentPinnedBad, _ref$CommentReactionB = _ref.CommentReactionButton, CommentReactionButton = _ref$CommentReactionB === void 0 ? _chunkPXTVW3TOjs.CommentReactionButton_default : _ref$CommentReactionB, _ref$profilePath = _ref.profilePath, profilePath = _ref$profilePath === void 0 ? "/profile" : _ref$profilePath;
  var _useRefetchableFragme = _reactrelay.useRefetchableFragment.call(void 0, _chunkNMH52K53js.CommentItemFragmentQuery, commentRef), _useRefetchableFragme2 = _slicedToArray(_useRefetchableFragme, 2), comment = _useRefetchableFragme2[0], refetchCommentItem = _useRefetchableFragme2[1];
  var _useCommentReply = _chunkIRF4AGBWjs.useCommentReply_default.call(void 0, ), setCommentReply = _useCommentReply.setCommentReply;
  var router = _navigation.useRouter.call(void 0, );
  var commentItemRef = _react.useRef.call(void 0, void 0);
  var _useState = _react.useState.call(void 0, false), _useState2 = _slicedToArray(_useState, 2), isEditMode = _useState2[0], setIsEditMode = _useState2[1];
  var _useState3 = _react.useState.call(void 0, false), _useState4 = _slicedToArray(_useState3, 2), isReplyExpanded = _useState4[0], setIsReplyExpanded = _useState4[1];
  var defaultCommentOptions = _chunkYU7MWHBQjs.useCommentOptions_default.call(void 0, {
    comment,
    onEdit: function onEdit() {
      return setIsEditMode(true);
    }
  });
  var _ref2 = ActionOverlayProps !== null && ActionOverlayProps !== void 0 ? ActionOverlayProps : {}, _ref2$actions = _ref2.actions, actions = _ref2$actions === void 0 ? defaultCommentOptions : _ref2$actions, restOfActionOverlayProps = _objectWithoutProperties(_ref2, _excluded);
  var _useTransition = _react.useTransition.call(void 0, ), _useTransition2 = _slicedToArray(_useTransition, 2), isLoadingReplies = _useTransition2[0], startLoadingReplies = _useTransition2[1];
  var _useCommentReply2 = _chunkIRF4AGBWjs.useCommentReply_default.call(void 0, ), resetCommentReply = _useCommentReply2.resetCommentReply;
  var _useCommentDeleteMuta = _chunkBWGH36W2js.useCommentDeleteMutation.call(void 0, ), _useCommentDeleteMuta2 = _slicedToArray(_useCommentDeleteMuta, 2), deleteComment = _useCommentDeleteMuta2[0], isDeletingComment = _useCommentDeleteMuta2[1];
  var profileUrl = "".concat(profilePath, "/").concat(comment === null || comment === void 0 || (_comment$user = comment.user) === null || _comment$user === void 0 ? void 0 : _comment$user.pk);
  var showReplies = function showReplies2() {
    if (isReplyExpanded) return;
    startLoadingReplies(function() {
      refetchCommentItem({
        isRepliesExpanded: true
      }, {
        fetchPolicy: "store-or-network",
        onComplete: function onComplete(error) {
          if (error) {
            console.error(error);
          } else {
            setIsReplyExpanded(true);
          }
        }
      });
    });
  };
  var replyToComment = function replyToComment2() {
    var _comment$user2;
    onReplyClick === null || onReplyClick === void 0 || onReplyClick();
    setCommentReply({
      commentItemRef,
      inReplyToId: comment.id,
      name: (_comment$user2 = comment.user) === null || _comment$user2 === void 0 ? void 0 : _comment$user2.fullName
    });
    showReplies();
  };
  var renderCommentContent = function renderCommentContent2() {
    if (isEditMode) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CommentUpdate, _objectSpread({
      comment,
      onCancel: function onCancel() {
        return setIsEditMode(false);
      }
    }, CommentUpdateProps));
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
      variant: "body2",
      sx: {
        whiteSpace: "pre-wrap",
        wordBreak: "normal",
        overflowWrap: "anywhere"
      },
      children: comment.body
    });
  };
  if (!comment) {
    return null;
  }
  var handleDeleteComment = function handleDeleteComment2() {
    deleteComment({
      variables: {
        id: comment.id
      }
    });
    resetCommentReply();
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
    children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkHEJJ6AAFjs.CommentContainerWrapper, {
      currentThreadDepth,
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkIFVB5H42js.ActionsOverlay_default, _objectSpread(_objectSpread({
        actions,
        showDeleteButton: enableDelete && comment.canDelete,
        handleDeleteItem: handleDeleteComment,
        isDeletingItem: isDeletingComment,
        title: "Comment"
      }, restOfActionOverlayProps), {}, {
        ref: commentItemRef,
        children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkHEJJ6AAFjs.CommentContainer, {
          children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _avatars.ClickableAvatar, {
            width: 40,
            height: 40,
            alt: (_comment$user$fullNam = (_comment$user3 = comment.user) === null || _comment$user3 === void 0 ? void 0 : _comment$user3.fullName) !== null && _comment$user$fullNam !== void 0 ? _comment$user$fullNam : "Comment's user avatar",
            src: (_comment$user4 = comment.user) === null || _comment$user4 === void 0 || (_comment$user4 = _comment$user4.avatar) === null || _comment$user4 === void 0 ? void 0 : _comment$user4.url,
            onClick: function onClick() {
              return router.push(profileUrl);
            }
          }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
            className: "grid gap-3",
            children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
              className: "grid grid-cols-1 justify-start",
              children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
                className: "grid grid-cols-[repeat(2,max-content)] items-center gap-2",
                children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _link2.default, {
                  href: profileUrl,
                  children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                    variant: "subtitle2",
                    children: (_comment$user5 = comment.user) === null || _comment$user5 === void 0 ? void 0 : _comment$user5.fullName
                  })
                }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CommentPinnedBadge, {
                  isPinned: comment.isPinned
                })]
              }), renderCommentContent()]
            }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
              className: "flex justify-between",
              children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
                className: "grid grid-cols-[repeat(2,max-content)] gap-4",
                children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, CommentReactionButton, {
                  target: comment
                }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CommentReplyButton, {
                  onReply: replyToComment,
                  isLoadingReplies,
                  commentId: comment.id,
                  totalCommentsCount: comment.commentsCount.total
                })]
              }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Timestamp, {
                date: comment.created
              })]
            })]
          })]
        })
      }))
    }), isReplyExpanded && !isLoadingReplies && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY7ZIW6UQjs.CommentsReplies_default, _objectSpread({
      target: comment,
      currentThreadDepth: currentThreadDepth + 1,
      subscriptionsEnabled,
      onReplyClick,
      CommentItem: _CommentItem
    }, CommentsRepliesProps), "replies-of-".concat(comment.id))]
  });
};
var CommentItem_default = _CommentItem;



exports.CommentItem_default = CommentItem_default;
//# sourceMappingURL=chunk-SPSXLSAR.js.map