import * as Handlebars from "handlebars";
import getHandlebarsHelpers from "./getHandlebarsHelpers";
/**
 * Render a lump of handlebars
 */
export default function renderHandlebars(templateStr, data, options) {
  for (const partial of (options === null || options === void 0 ? void 0 : options.partials) || []) {
    Handlebars.registerPartial(partial.id, (partial === null || partial === void 0 ? void 0 : partial.html) || "");
  }
  try {
    const helpers = (options === null || options === void 0 ? void 0 : options.helpers) || getHandlebarsHelpers();
    for (const [helperName, helperFn] of Object.entries(helpers)) {
      try {
        if (this.currentHelpers.includes(helperName))
          Handlebars.unregisterHelper(helperName);
        Handlebars.registerHelper(helperName, helperFn);
        if (!this.currentHelpers.includes(helperName))
          this.currentHelpers = [...this.currentHelpers, helperName];
      }
      catch (_a) {
        console.log(`Error setting helper ${helperName}.`);
      }
    }
  }
  catch (_b) {
    console.log("Error setting helpers.");
  }
  return Handlebars.compile(templateStr)(data);
}
//# sourceMappingURL=renderHandlebars.js.map