"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
exports.resendMessage = resendMessage;
var _clientRegistry = require("./clientRegistry");
var _roomStore = require("../roomStore");
var _roomsSlice = require("../roomStore/roomsSlice");
var _uuid = require("uuid");
async function resendMessage(message, options = {}) {
  const client = (0, _clientRegistry.requireXmppClient)();
  const state = _roomStore.store.getState();
  const user = state.chatSettingStore.user;
  const config = state.chatSettingStore.config;
  const activeRoomJID = message.roomJid;
  const id = `resend-text-message-${(0, _uuid.v4)()}`;
  _roomStore.store.dispatch((0, _roomsSlice.addRoomMessage)({
    roomJID: activeRoomJID,
    message: {
      id,
      user: {
        ...user,
        id: user.xmppUsername || '',
        name: user.firstName + ' ' + user.lastName
      },
      date: new Date().toISOString(),
      body: message.body,
      roomJid: activeRoomJID,
      xmppFrom: `${activeRoomJID}/${user.xmppUsername}`,
      pending: true,
      isReply: message.isReply || false,
      showInChannel: message.showInChannel || 'false',
      mainMessage: message.mainMessage || ''
    }
  }));
  const useTranslate = !!(options.respectTranslateConfig && config?.translates?.enabled);
  if (useTranslate) {
    client.sendTextMessageWithTranslateTagStanza(activeRoomJID, user.firstName, user.lastName, '', user.walletAddress, message.body, '', message.isReply || false, message.showInChannel === 'true' || false, message.mainMessage || '', state.chatSettingStore.langSource || 'en', id);
  } else {
    client.sendMessage(activeRoomJID, user.firstName, user.lastName, '', user.walletAddress, message.body, '', message.isReply || false, message.showInChannel === 'true' || false, message.mainMessage || '', id);
  }
  return id;
}
var _default = exports.default = resendMessage;
//# sourceMappingURL=resendMessage.js.map