import { fetcher } from "../fetcher.mjs";
import { built_default } from "../config/dist/esm/built.mjs";

//#region ../@intlayer/cli/dist/esm/api/dist/esm/getIntlayerAPI/newsletter.mjs
const getNewsletterAPI = (authAPIOptions = {}, intlayerConfig) => {
	const backendURL = intlayerConfig?.editor?.backendURL ?? built_default?.editor?.backendURL;
	if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
	const NEWSLETTER_API_ROUTE = `${backendURL}/api/newsletter`;
	/**
	* Subscribe a user to newsletter(s)
	* @param body - Newsletter subscription parameters.
	* @returns Newsletter subscription result.
	*/
	const subscribeToNewsletter = async (body, otherOptions = {}) => await fetcher(`${NEWSLETTER_API_ROUTE}/subscribe`, authAPIOptions, otherOptions, {
		method: "POST",
		body
	});
	/**
	* Unsubscribe a user from newsletter(s)
	* @param body - Newsletter unsubscription parameters.
	* @returns Newsletter unsubscription result.
	*/
	const unsubscribeFromNewsletter = async (body, otherOptions = {}) => await fetcher(`${NEWSLETTER_API_ROUTE}/unsubscribe`, authAPIOptions, otherOptions, {
		method: "POST",
		body
	});
	/**
	* Get newsletter subscription status for the authenticated user
	* @returns Newsletter subscription status.
	*/
	const getNewsletterStatus = async (otherOptions = {}) => await fetcher(`${NEWSLETTER_API_ROUTE}/status`, authAPIOptions, otherOptions, { method: "GET" });
	return {
		subscribeToNewsletter,
		unsubscribeFromNewsletter,
		getNewsletterStatus
	};
};

//#endregion
export { getNewsletterAPI };
//# sourceMappingURL=newsletter.mjs.map