import fs from "fs";
import path from "path";

export function renderEmailTemplate(
  templateName: string,
  variables: Record<string, string>
): string {
  const templatePath = path.join(__dirname, "../emails", templateName);
  let html = fs.readFileSync(templatePath, "utf8");

  // Replace placeholders like {{first_name}}
  for (const key in variables) {
    const value = variables[key];
    const regex = new RegExp(`{{${key}}}`, "g");
    html = html.replace(regex, value);
  }

  return html;
}
