import { templateRender } from "vue-email/compiler";
import { useRuntimeConfig, useStorage } from "#imports";
const storageKey = "assets:emails";
export async function useCompiler(filename, data, verbose = false) {
  const vueEmailOptions = useRuntimeConfig().public.vueEmailOptions;
  const source = await useStorage(storageKey).getItem(filename);
  const keys = await useStorage(storageKey).getKeys();
  const components = [];
  for (const key of keys) {
    const value = await useStorage(storageKey).getItem(key);
    if (value) {
      components.push({
        name: key,
        source: value
      });
    }
  }
  const template = await templateRender(filename, { source, components }, data, {
    verbose,
    options: vueEmailOptions
  });
  return template;
}
