const handlebars = require('handlebars');
const path = require('path');
const fs = require('fs');
const data = require('./data');

function compile(isDevMode = false) {
  const templatePath = path.resolve(__dirname, 'index.html.handlebars');
  const template = fs.readFileSync(templatePath).toString();
  const compiled = handlebars.compile(template);
  let result;
  if (isDevMode) {
    result = compiled(data.dev);
  } else {
    result = compiled(data.prod);
  }

  return result;
}

exports.compile = compile;
