import configuration from "@intlayer/config/built";
import { createAuthClient } from "better-auth/client";

//#region src/libs/auth.ts
const getAuthAPI = (intlayerConfig) => {
	const backendURL = intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;
	if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
	const getAuthClient = () => {
		return createAuthClient({
			baseURL: backendURL,
			withCredentials: true
		});
	};
	const signInEmail = async (...args) => {
		return getAuthClient().signIn.email(...args);
	};
	const signInSocial = async (...args) => {
		return getAuthClient().signIn.social(...args);
	};
	const signUpEmail = async (...args) => {
		return getAuthClient().signUp.email(...args);
	};
	const signOut = async (...args) => {
		return getAuthClient().signOut(...args);
	};
	const changePasswordSession = async (...args) => {
		return getAuthClient().changePassword(...args);
	};
	const requestPasswordResetSession = async (...args) => {
		return getAuthClient().requestPasswordReset(...args);
	};
	const resetPassword = async (...args) => {
		return getAuthClient().resetPassword(...args);
	};
	const verifyEmailSession = async (...args) => {
		return getAuthClient().verifyEmail(...args);
	};
	const getSession = async (...args) => {
		return getAuthClient().getSession(...args);
	};
	const forgetPassword = async (...args) => {
		return getAuthClient().forgetPassword(...args);
	};
	const sendVerificationEmail = async (...args) => {
		return getAuthClient().sendVerificationEmail(...args);
	};
	const changeEmail = async (...args) => {
		return getAuthClient().changeEmail(...args);
	};
	const deleteUser = async (...args) => {
		return getAuthClient().deleteUser(...args);
	};
	const revokeSession = async (...args) => {
		return getAuthClient().revokeSession(...args);
	};
	const revokeSessions = async (...args) => {
		return getAuthClient().revokeSessions(...args);
	};
	const revokeOtherSessions = async (...args) => {
		return getAuthClient().revokeOtherSessions(...args);
	};
	const linkSocial = async (...args) => {
		return getAuthClient().linkSocial(...args);
	};
	const listAccounts = async (...args) => {
		return getAuthClient().listAccounts(...args);
	};
	const unlinkAccount = async (...args) => {
		return getAuthClient().unlinkAccount(...args);
	};
	const refreshToken = async (...args) => {
		return getAuthClient().refreshToken(...args);
	};
	const getAccessToken = async (...args) => {
		return getAuthClient().getAccessToken(...args);
	};
	const accountInfo = async (...args) => {
		return getAuthClient().accountInfo(...args);
	};
	const updateUser = async (...args) => {
		return getAuthClient().updateUser(...args);
	};
	const listSessions = async (...args) => {
		return getAuthClient().listSessions(...args);
	};
	return {
		getAuthClient,
		signInEmail,
		signUpEmail,
		signOut,
		signInSocial,
		linkSocial,
		changePasswordSession,
		requestPasswordResetSession,
		resetPassword,
		verifyEmailSession,
		getSession,
		forgetPassword,
		sendVerificationEmail,
		changeEmail,
		deleteUser,
		revokeSession,
		revokeSessions,
		revokeOtherSessions,
		listAccounts,
		unlinkAccount,
		refreshToken,
		getAccessToken,
		accountInfo,
		updateUser,
		listSessions
	};
};

//#endregion
export { getAuthAPI };
//# sourceMappingURL=auth.mjs.map