import { IGenericSection } from '../../../../generic/types';
import { IRWCMessage } from '../../../types';
import { getMethods } from '../methods';

export const transformContext = ({ children }: IGenericSection, isPlain:boolean): IRWCMessage => {
  const words = children.map(item => {
    const child = getMethods(item.type)(item, true);
    return {
      type: item.type,
      message: child?.message || child || ''
    };
  });

  if (isPlain) {
    return {
      message: words.map(w => w.message).join(" ")
    };
  }

  const message = words.map(w => {
    if (w.type === 'text') {
      return `<span style="margin-right: 5px;">${w.message}</span>`;
    }
    if (w.type === 'image') {
      return `<img src="${w.message}" style="height: 20px; margin-right: 5px;" />`;
    }
    return w.message;
  }).join("");

  return {
    message: `<div style="display: flex; flex-wrap: wrap; color: rgb(97, 96, 97); font-size: 13px;">${message}</div>`
  };
};