"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MessageContainer = void 0;
var _react = _interopRequireWildcard(require("react"));
var _DateLabel = _interopRequireDefault(require("../styled/DateLabel"));
var _SystemMessage = _interopRequireDefault(require("./SystemMessage"));
var _NewMessageLabel = _interopRequireDefault(require("../styled/NewMessageLabel"));
var _StyledComponents = require("../styled/StyledComponents");
var _reactNative = require("react-native");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const MessageContainer = ({
  CustomMessage,
  CustomDaySeparator,
  CustomNewMessageLabel,
  message,
  activeMessage,
  config,
  walletAddress,
  showDateLabel,
  isReply,
  className
}) => {
  const isUser = message.user.id === walletAddress;
  const messageDate = new Date(message.date);
  if (message?.isSystemMessage === 'true') {
    const SystemMessageComponent = config?.customSystemMessage;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
      children: [showDateLabel && (CustomDaySeparator ? /*#__PURE__*/(0, _jsxRuntime.jsx)(CustomDaySeparator, {
        date: messageDate,
        formattedDate: messageDate.toLocaleDateString()
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateLabel.default, {
        date: messageDate,
        colors: config?.colors
      })), SystemMessageComponent ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SystemMessageComponent, {
        message: message,
        isUser: false,
        isReply: false
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_SystemMessage.default, {
        messageText: message.body,
        colors: config?.colors
      })]
    }, message.id);
  }
  if (String(message?.id || '').startsWith('delimiter-new')) {
    return CustomNewMessageLabel ? /*#__PURE__*/(0, _jsxRuntime.jsx)(CustomNewMessageLabel, {
      color: config?.colors?.primary
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_NewMessageLabel.default, {
      color: config?.colors?.primary
    });
  }
  const MessageComponent = CustomMessage || _StyledComponents.Message;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    children: [showDateLabel && !activeMessage && !String(message.id || '').startsWith('delimiter-new') ? CustomDaySeparator ? /*#__PURE__*/(0, _jsxRuntime.jsx)(CustomDaySeparator, {
      date: messageDate,
      formattedDate: messageDate.toLocaleDateString()
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateLabel.default, {
      date: messageDate,
      colors: config?.colors
    }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(MessageComponent, {
      message: message,
      isUser: isUser,
      isReply: isReply,
      className: className,
      children: !CustomMessage ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.MessageTimestamp, {
          children: messageDate.toLocaleTimeString()
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledComponents.UserName, {
          children: [message.user.name, ": "]
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.MessageText, {
          children: message.body
        })]
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(MessageComponent, {
        message: message,
        isUser: isUser,
        isReply: isReply
      })
    })]
  }, message.id);
};
exports.MessageContainer = MessageContainer;
//# sourceMappingURL=MessageContainer.js.map