import nodemailer from 'nodemailer';

const transporter = nodemailer.createTransport({
    host: process.env.EMAIL_SMTP,
    port: process.env.EMAIL_PORT,
    secure: true,
    auth: {
        user: process.env.EMAIL_USER,
        pass: process.env.EMAIL_PASS
    }
});

const baseMail = (title, body) => {
    return `
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1.0" />
            <style>
            body {
                font-family: Arial, sans-serif;
                margin: 0;
                padding: 0;
                background-color: #f4f4f4;
            }
            .email-container {
                max-width: 600px;
                margin: 20px auto;
                background-color: #ffffff;
                border-radius: 8px;
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
                overflow: hidden;
            }
            .email-header {
                background-color: #007bff;
                color: #ffffff;
                text-align: center;
                padding: 20px;
            }
            .email-body {
                padding: 20px;
                color: #333333;
                line-height: 1.5;
            }
            .email-button {
                display: inline-block;
                margin: 20px 0;
                padding: 10px 20px;
                background-color: #007bff;
                color: #ffffff !important;
                text-decoration: none;
                border-radius: 5px;
                text-align: center;
            }
            .email-footer {
                text-align: center;
                padding: 10px 20px;
                background-color: #f4f4f4;
                color: #999999;
                font-size: 12px;
            }
            .email-footer a {
                color: #007bff;
                text-decoration: none;
            }
            </style>
        </head>
        <body>
            <div class="email-container">
            <!-- En-tête -->
            <div class="email-header">
                <img src="https://github.com/Absolument-Oui/InfoGare/blob/website/src/favicon.png?raw=true" alt="Logo" width="50" height="50" />
                <h1>${title}</h1>
            </div>

            <!-- Corps du message -->
            <div class="email-body">
                ${body}
            </div>

            <!-- Pied de page -->
            <div class="email-footer">
                <p>
                Vous recevez cet email parce que vous vous êtes inscrit sur InfoGare.
                </p>
                <p>
                <a href="https://infogare.fr/unsubscribe">Se désabonner</a> | 
                <a href="https://infogare.fr">Site InfoGare</a>
                </p>
            </div>
            </div>
        </body>
        </html>
    `;
}

export { baseMail, transporter };