import { l as lib } from './index-9ae23364.js';
import { g as getHandlebarsHelpers } from './getHandlebarsHelpers-0376b57c.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) || []) {
    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();
    for (const [helperName, helperFn] of Object.entries(helpers)) {
      try {
        if (currentHelpers.includes(helperName))
          lib.unregisterHelper(helperName);
        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 lib.compile(templateStr)(data);
}

export { renderHandlebars as r };
