import { markdownToHtml } from '@defra/forms-model';
import { engine } from "./helpers.js";
import { plugin } from "./plugin.js";
import { checkComponentTemplates, checkErrorTemplates, evaluate, govukRebrand } from "../nunjucks/environment.js";
import * as filters from "../nunjucks/filters/index.js";
export { getPageHref } from "./helpers.js";
export { context } from "../nunjucks/context.js";
const globals = {
  checkComponentTemplates,
  checkErrorTemplates,
  evaluate,
  govukRebrand
};
export const VIEW_PATH = 'src/server/plugins/engine/views';
export const PLUGIN_PATH = 'node_modules/@defra/forms-engine-plugin';
export const prepareNunjucksEnvironment = function (env, pluginOptions) {
  for (const [name, nunjucksFilter] of Object.entries(filters)) {
    env.addFilter(name, nunjucksFilter);
  }
  env.addFilter('markdown', text => markdownToHtml(text, pluginOptions.baseUrl));
  for (const [name, nunjucksGlobal] of Object.entries(globals)) {
    env.addGlobal(name, nunjucksGlobal);
  }

  // Apply any additional filters to both the liquid and nunjucks engines
  if (pluginOptions.filters) {
    for (const [name, filter] of Object.entries(pluginOptions.filters)) {
      env.addFilter(name, filter);
      engine.registerFilter(name, filter);
    }
  }

  // Apply any additional globals to nunjucks engines
  if (pluginOptions.globals) {
    Object.entries(pluginOptions.globals).forEach(([name, fn]) => {
      env.addGlobal(name, fn);
    });
  }
};
export default plugin;
//# sourceMappingURL=index.js.map