import Layout from 'emailer/emails/layouts/MainLayout.jsx';
import { Container } from '@react-email/components';

type MassEmailProps = {
  subject: string;
  content: string;
  greeting?: string;
  firstName?: string;
  fullName?: string;
};

const Email = ({ content, greeting, firstName, fullName }: MassEmailProps) => {
  const processGreeting = (text: string) => {
    return text.replace(/\{\{firstName\}\}/g, firstName || '').replace(/\{\{fullName\}\}/g, fullName || '');
  };

  const processedGreeting = greeting ? processGreeting(greeting) : '';
  const greetingHtml = processedGreeting ? `<p>${processedGreeting}</p>` : '';

  return (
    <Layout>
      <Container>
        <div dangerouslySetInnerHTML={{ __html: greetingHtml + content }} />
      </Container>
    </Layout>
  );
};

export default Email;
