import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
import { resolveEntrypoint } from "../utils.js";
function validateMod(mod, entrypoint) {
  try {
    if (typeof mod !== "object" || mod === null) {
      throw new Error(`Expected an object for the module, but received ${typeof mod}.`);
    }
    if (typeof mod.provider !== "function") {
      throw new Error(`Invalid provider export in module, expected a function.`);
    }
    return {
      provider: mod.provider
    };
  } catch (cause) {
    throw new AstroError(
      {
        ...AstroErrorData.CannotLoadFontProvider,
        message: AstroErrorData.CannotLoadFontProvider.message(entrypoint)
      },
      { cause }
    );
  }
}
async function resolveProvider({
  root,
  provider: { entrypoint, config },
  resolveMod
}) {
  const id = resolveEntrypoint(root, entrypoint.toString()).href;
  const mod = await resolveMod(id);
  const { provider } = validateMod(mod, id);
  return { config, provider };
}
export {
  resolveProvider,
  validateMod
};
