const path = require("path");
require("dotenv").config({
  path: path.resolve(
    process.cwd(),
    `.env.${process.env.NODE_ENV || "development"}`
  ),
});
const logger = require("../utils/logger");
const inlineCssTool = require("inline-css");

exports.inlinecss = (req, res) => {
  //Perform request validation

  logger.log("email-inline-css", "DEBUG", req.user.email, null, null);

  const { html, url } = req.body;

  inlineCssTool(html, { url: url })
    .then((inlinedHtml) => {
      res.send(inlinedHtml);
    })
    .catch((error) => {
      logger.log("email-inline-css-error", "ERROR", req.user.email, null, {
        error,
      });

      res.send(error);
    });
};
