import { logger } from "../logger/index.mjs";
import { InviteUserEmailEN, InviteUserEmailES, InviteUserEmailFR } from "../emails/InviteUserEmail.mjs";
import { MagicLinkEmailEN, MagicLinkEmailES, MagicLinkEmailFR } from "../emails/MagicLinkEmail.mjs";
import { OAuthTokenCreatedEmailEN, OAuthTokenCreatedEmailES, OAuthTokenCreatedEmailFR } from "../emails/OAuthTokenCreatedEmail.mjs";
import { PasswordChangeConfirmationEmailEN, PasswordChangeConfirmationEmailES, PasswordChangeConfirmationEmailFR } from "../emails/PasswordChangeConfirmation.mjs";
import { ResetPasswordEmailEN, ResetPasswordEmailES, ResetPasswordEmailFR } from "../emails/ResetUserPassword.mjs";
import { SubscriptionPaymentCancellationEN, SubscriptionPaymentCancellationES, SubscriptionPaymentCancellationFR } from "../emails/SubscriptionPaymentCancellation.mjs";
import { SubscriptionPaymentErrorEN, SubscriptionPaymentErrorES, SubscriptionPaymentErrorFR } from "../emails/SubscriptionPaymentError.mjs";
import { SubscriptionPaymentSuccessEN, SubscriptionPaymentSuccessES, SubscriptionPaymentSuccessFR } from "../emails/SubscriptionPaymentSuccess.mjs";
import { ValidateUserEmailEN, ValidateUserEmailES, ValidateUserEmailFR } from "../emails/ValidateUserEmail.mjs";
import { WelcomeEmailEN, WelcomeEmailES, WelcomeEmailFR } from "../emails/Welcome.mjs";
import { t } from "express-intlayer";
import { jsx } from "react/jsx-runtime";
import { Resend } from "resend";

//#region src/services/email.service.tsx
const getEmailComponents = (locale) => ({
	invite: {
		template: t({
			en: InviteUserEmailEN,
			fr: InviteUserEmailFR,
			es: InviteUserEmailES
		}, locale),
		subject: 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: t({
			en: ValidateUserEmailEN,
			fr: ValidateUserEmailFR,
			es: ValidateUserEmailES
		}, locale),
		subject: t({
			en: "Validate your email for Intlayer",
			fr: "Validez votre email pour Intlayer",
			es: "Valida tu correo electrónico para Intlayer"
		}, locale)
	},
	resetPassword: {
		template: t({
			en: ResetPasswordEmailEN,
			fr: ResetPasswordEmailFR,
			es: ResetPasswordEmailES
		}, locale),
		subject: 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: t({
			en: WelcomeEmailEN,
			fr: WelcomeEmailFR,
			es: WelcomeEmailES
		}, locale),
		subject: t({
			en: "Welcome to Intlayer!",
			fr: "Bienvenue chez Intlayer!",
			es: "¡Bienvenido a Intlayer!"
		}, locale)
	},
	magicLink: {
		template: t({
			en: MagicLinkEmailEN,
			fr: MagicLinkEmailFR,
			es: MagicLinkEmailES
		}, locale),
		subject: t({
			en: "Sign in to Intlayer",
			fr: "Connectez-vous à Intlayer",
			es: "Inicia sesión en Intlayer"
		}, locale)
	},
	passwordChangeConfirmation: {
		template: t({
			en: PasswordChangeConfirmationEmailEN,
			fr: PasswordChangeConfirmationEmailFR,
			es: PasswordChangeConfirmationEmailES
		}, locale),
		subject: 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: t({
			en: SubscriptionPaymentSuccessEN,
			fr: SubscriptionPaymentSuccessFR,
			es: SubscriptionPaymentSuccessES
		}),
		subject: 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: t({
			en: SubscriptionPaymentCancellationEN,
			fr: SubscriptionPaymentCancellationFR,
			es: SubscriptionPaymentCancellationES
		}),
		subject: 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: t({
			en: SubscriptionPaymentErrorEN,
			fr: SubscriptionPaymentErrorFR,
			es: SubscriptionPaymentErrorES
		}),
		subject: 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: t({
			en: OAuthTokenCreatedEmailEN,
			fr: OAuthTokenCreatedEmailFR,
			es: OAuthTokenCreatedEmailES
		}),
		subject: 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 = new Resend(process.env.RESEND_API_KEY);
	const { template, subject: baseSubject } = getEmailComponents(locale)[type];
	const react = /* @__PURE__ */ jsx(template, { ...props });
	await resend.emails.send({
		from: "Intlayer <no-reply@intlayer.org>",
		to,
		subject: subject ?? baseSubject,
		react
	}).catch((err) => logger.error(err));
	logger.info(`Email sent ${type} to ${to}`);
};

//#endregion
export { sendEmail };
//# sourceMappingURL=email.service.mjs.map