"use strict";

import { requireXmppClient } from './clientRegistry';
import { store } from '../roomStore';
import { addRoomMessage } from '../roomStore/roomsSlice';
import { v4 as uuidv4 } from 'uuid';
export async function resendMessage(message, options = {}) {
  const client = requireXmppClient();
  const state = store.getState();
  const user = state.chatSettingStore.user;
  const config = state.chatSettingStore.config;
  const activeRoomJID = message.roomJid;
  const id = `resend-text-message-${uuidv4()}`;
  store.dispatch(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;
}
export default resendMessage;
//# sourceMappingURL=resendMessage.js.map