'use strict';

const index = require('./index-30292d33.js');
const getHandlebarsHelpers = require('./getHandlebarsHelpers-7b2b1728.js');

let currentHelpers = [];
/**
 * Render a lump of handlebars
 */
function renderHandlebars(templateStr, data, options) {
  for (const partial of (options === null || options === void 0 ? void 0 : options.partials) || []) {
    index.lib.registerPartial(partial.id, (partial === null || partial === void 0 ? void 0 : partial.html) || "");
  }
  try {
    const helpers = Object.keys((options === null || options === void 0 ? void 0 : options.helpers) || []).length
      ? options.helpers
      : getHandlebarsHelpers.getHandlebarsHelpers();
    for (const [helperName, helperFn] of Object.entries(helpers)) {
      try {
        if (currentHelpers.includes(helperName))
          index.lib.unregisterHelper(helperName);
        index.lib.registerHelper(helperName, helperFn);
        if (!currentHelpers.includes(helperName))
          currentHelpers = [...currentHelpers, helperName];
      }
      catch (error) {
        console.log(`Error setting helper ${helperName}.`, error);
      }
    }
  }
  catch (_a) {
    console.log("Error setting helpers.");
  }
  return index.lib.compile(templateStr)(data);
}

exports.renderHandlebars = renderHandlebars;
