"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _StyledRoomComponents = require("./StyledRoomComponents");
var _parseMessageBody = require("../../../helpers/parseMessageBody");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getPlainText = body => {
  if (!body || typeof body !== 'string') {
    return 'Chat created';
  }
  let text = (0, _parseMessageBody.decodeHTMLEntities)(body);
  text = text.replace(/^#{1,6}\s+/gm, '');
  text = text.replace(/\*\*([^*]+)\*\*/g, '$1');
  text = text.replace(/__([^_]+)__/g, '$1');
  text = text.replace(/\*([^*]+)\*/g, '$1');
  text = text.replace(/_([^_]+)_/g, '$1');
  text = text.replace(/~~([^~]+)~~/g, '$1');
  text = text.replace(/`([^`]+)`/g, '$1');
  text = text.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1');
  text = text.replace(/^[\s]*[-*+]\s+/gm, '');
  text = text.replace(/^\s*\d+\.\s+/gm, '');
  text = text.replace(/\|/g, ' ');
  text = text.replace(/```[\s\S]*?```/g, '');
  text = text.replace(/<[^>]+>/g, '');
  text = text.replace(/\s+/g, ' ');
  text = text.replace(/\n/g, ' ').trim();
  return text || 'Chat created';
};
const LastTextMessage = ({
  user,
  body
}) => {
  const plainText = getPlainText(body);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledRoomComponents.LastRoomMessageContainer, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledRoomComponents.LastRoomMessageName, {
      numberOfLines: 1,
      ellipsizeMode: "tail",
      children: user?.name
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledRoomComponents.LastRoomMessageText, {
      numberOfLines: 1,
      ellipsizeMode: "tail",
      children: plainText
    })]
  });
};
var _default = exports.default = LastTextMessage;
//# sourceMappingURL=LastTextMessage.js.map