"use strict";

import React, { Fragment } from 'react';
import DateLabel from '../styled/DateLabel';
import SystemMessage from './SystemMessage';
import NewMessageLabel from '../styled/NewMessageLabel';
import { Message, MessageText, MessageTimestamp, UserName } from '../styled/StyledComponents';
import { View } from 'react-native';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
export 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__*/_jsxs(Fragment, {
      children: [showDateLabel && (CustomDaySeparator ? /*#__PURE__*/_jsx(CustomDaySeparator, {
        date: messageDate,
        formattedDate: messageDate.toLocaleDateString()
      }) : /*#__PURE__*/_jsx(DateLabel, {
        date: messageDate,
        colors: config?.colors
      })), SystemMessageComponent ? /*#__PURE__*/_jsx(SystemMessageComponent, {
        message: message,
        isUser: false,
        isReply: false
      }) : /*#__PURE__*/_jsx(SystemMessage, {
        messageText: message.body,
        colors: config?.colors
      })]
    }, message.id);
  }
  if (String(message?.id || '').startsWith('delimiter-new')) {
    return CustomNewMessageLabel ? /*#__PURE__*/_jsx(CustomNewMessageLabel, {
      color: config?.colors?.primary
    }) : /*#__PURE__*/_jsx(NewMessageLabel, {
      color: config?.colors?.primary
    });
  }
  const MessageComponent = CustomMessage || Message;
  return /*#__PURE__*/_jsxs(View, {
    children: [showDateLabel && !activeMessage && !String(message.id || '').startsWith('delimiter-new') ? CustomDaySeparator ? /*#__PURE__*/_jsx(CustomDaySeparator, {
      date: messageDate,
      formattedDate: messageDate.toLocaleDateString()
    }) : /*#__PURE__*/_jsx(DateLabel, {
      date: messageDate,
      colors: config?.colors
    }) : null, /*#__PURE__*/_jsx(MessageComponent, {
      message: message,
      isUser: isUser,
      isReply: isReply,
      className: className,
      children: !CustomMessage ? /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(MessageTimestamp, {
          children: messageDate.toLocaleTimeString()
        }), /*#__PURE__*/_jsxs(UserName, {
          children: [message.user.name, ": "]
        }), /*#__PURE__*/_jsx(MessageText, {
          children: message.body
        })]
      }) : /*#__PURE__*/_jsx(MessageComponent, {
        message: message,
        isUser: isUser,
        isReply: isReply
      })
    })]
  }, message.id);
};
//# sourceMappingURL=MessageContainer.js.map