const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
const require_logger_index = require('../logger/index.cjs');
const require_emails_InviteUserEmail = require('../emails/InviteUserEmail.cjs');
const require_emails_OAuthTokenCreatedEmail = require('../emails/OAuthTokenCreatedEmail.cjs');
const require_emails_PasswordChangeConfirmation = require('../emails/PasswordChangeConfirmation.cjs');
const require_emails_ResetUserPassword = require('../emails/ResetUserPassword.cjs');
const require_emails_SubscriptionPaymentCancellation = require('../emails/SubscriptionPaymentCancellation.cjs');
const require_emails_SubscriptionPaymentError = require('../emails/SubscriptionPaymentError.cjs');
const require_emails_SubscriptionPaymentSuccess = require('../emails/SubscriptionPaymentSuccess.cjs');
const require_emails_ValidateUserEmail = require('../emails/ValidateUserEmail.cjs');
const require_emails_Welcome = require('../emails/Welcome.cjs');
let express_intlayer = require("express-intlayer");
let react_jsx_runtime = require("react/jsx-runtime");
let resend = require("resend");

//#region src/services/email.service.tsx
const getEmailComponents = (locale) => ({
	invite: {
		template: (0, express_intlayer.t)({
			en: require_emails_InviteUserEmail.InviteUserEmailEN,
			fr: require_emails_InviteUserEmail.InviteUserEmailFR,
			es: require_emails_InviteUserEmail.InviteUserEmailES
		}, locale),
		subject: (0, express_intlayer.t)({
			en: "You have been invited to join Intlayer",
			fr: "Vous êtes invité à rejoindre Intlayer",
			es: "Has sido invitado a unirte a Intlayer"
		}, locale)
	},
	validate: {
		template: (0, express_intlayer.t)({
			en: require_emails_ValidateUserEmail.ValidateUserEmailEN,
			fr: require_emails_ValidateUserEmail.ValidateUserEmailFR,
			es: require_emails_ValidateUserEmail.ValidateUserEmailES
		}, locale),
		subject: (0, express_intlayer.t)({
			en: "Validate your email for Intlayer",
			fr: "Validez votre email pour Intlayer",
			es: "Valida tu correo electrónico para Intlayer"
		}, locale)
	},
	resetPassword: {
		template: (0, express_intlayer.t)({
			en: require_emails_ResetUserPassword.ResetPasswordEmailEN,
			fr: require_emails_ResetUserPassword.ResetPasswordEmailFR,
			es: require_emails_ResetUserPassword.ResetPasswordEmailES
		}, locale),
		subject: (0, express_intlayer.t)({
			en: "Reset your password for Intlayer",
			fr: "Réinitialisez votre mot de passe pour Intlayer",
			es: "Restablece tu contraseña para Intlayer"
		}, locale)
	},
	welcome: {
		template: (0, express_intlayer.t)({
			en: require_emails_Welcome.WelcomeEmailEN,
			fr: require_emails_Welcome.WelcomeEmailFR,
			es: require_emails_Welcome.WelcomeEmailES
		}, locale),
		subject: (0, express_intlayer.t)({
			en: "Welcome to Intlayer!",
			fr: "Bienvenue chez Intlayer!",
			es: "¡Bienvenido a Intlayer!"
		}, locale)
	},
	passwordChangeConfirmation: {
		template: (0, express_intlayer.t)({
			en: require_emails_PasswordChangeConfirmation.PasswordChangeConfirmationEmailEN,
			fr: require_emails_PasswordChangeConfirmation.PasswordChangeConfirmationEmailFR,
			es: require_emails_PasswordChangeConfirmation.PasswordChangeConfirmationEmailES
		}, locale),
		subject: (0, express_intlayer.t)({
			en: "Your Intlayer password has been changed",
			fr: "Votre mot de passe Intlayer a été modifié",
			es: "Tu contraseña de Intlayer ha sido cambiada"
		}, locale)
	},
	subscriptionPaymentSuccess: {
		template: (0, express_intlayer.t)({
			en: require_emails_SubscriptionPaymentSuccess.SubscriptionPaymentSuccessEN,
			fr: require_emails_SubscriptionPaymentSuccess.SubscriptionPaymentSuccessFR,
			es: require_emails_SubscriptionPaymentSuccess.SubscriptionPaymentSuccessES
		}),
		subject: (0, express_intlayer.t)({
			en: "Your payment for Intlayer subscription is confirmed",
			fr: "Votre paiement pour l'abonnement Intlayer est confirmé",
			es: "Tu pago por la suscripción de Intlayer ha sido confirmado"
		})
	},
	subscriptionPaymentCancellation: {
		template: (0, express_intlayer.t)({
			en: require_emails_SubscriptionPaymentCancellation.SubscriptionPaymentCancellationEN,
			fr: require_emails_SubscriptionPaymentCancellation.SubscriptionPaymentCancellationFR,
			es: require_emails_SubscriptionPaymentCancellation.SubscriptionPaymentCancellationES
		}),
		subject: (0, express_intlayer.t)({
			en: "Your Intlayer subscription has been canceled",
			fr: "Votre abonnement Intlayer a été annulé",
			es: "Tu suscripción de Intlayer ha sido cancelada"
		})
	},
	subscriptionPaymentError: {
		template: (0, express_intlayer.t)({
			en: require_emails_SubscriptionPaymentError.SubscriptionPaymentErrorEN,
			fr: require_emails_SubscriptionPaymentError.SubscriptionPaymentErrorFR,
			es: require_emails_SubscriptionPaymentError.SubscriptionPaymentErrorES
		}),
		subject: (0, express_intlayer.t)({
			en: "There was an issue with your Intlayer subscription payment",
			fr: "Un problème est survenu avec votre paiement pour l'abonnement Intlayer",
			es: "Hubo un problema con el pago de tu suscripción de Intlayer"
		})
	},
	oAuthTokenCreated: {
		template: (0, express_intlayer.t)({
			en: require_emails_OAuthTokenCreatedEmail.OAuthTokenCreatedEmailEN,
			fr: require_emails_OAuthTokenCreatedEmail.OAuthTokenCreatedEmailFR,
			es: require_emails_OAuthTokenCreatedEmail.OAuthTokenCreatedEmailES
		}),
		subject: (0, express_intlayer.t)({
			en: "A third-party OAuth application has been added to your Intlayer account",
			fr: "Une application OAuth tierce a été ajoutée à votre compte Intlayer",
			es: "Una aplicación OAuth de terceros ha sido añadida a tu cuenta de Intlayer"
		})
	}
});
const sendEmail = async ({ type, to, subject, locale,...props }) => {
	const resend$1 = new resend.Resend(process.env.RESEND_API_KEY);
	const { template, subject: baseSubject } = getEmailComponents(locale)[type];
	const react = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(template, { ...props });
	await resend$1.emails.send({
		from: "Intlayer <no-reply@intlayer.org>",
		to,
		subject: subject ?? baseSubject,
		react
	}).catch((err) => require_logger_index.logger.error(err));
	require_logger_index.logger.info(`Email sent ${type} to ${to}`);
};

//#endregion
exports.sendEmail = sendEmail;
//# sourceMappingURL=email.service.cjs.map