const juice = require("juice");

exports.inlineCSS = async (req, res) => {
  const { logger } = req;
  const { html } = req.body;

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

  try {
    const inlinedHtml = juice(html, {
      applyAttributesTableElements: false,
      preserveMediaQueries: false,
      applyWidthAttributes: false
    });
    res.send(inlinedHtml);
  } catch (error) {
    logger.log("email-inline-css-error", "ERROR", req.user.email, null, {
      error
    });
    res.send(error.message);
  }
};
