from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
from django.urls import reverse
from django.contrib.sites.shortcuts import get_current_site
from django.contrib.auth.tokens import default_token_generator

def send_welcome_email(user, request):
    token = 'generated_token_here'
    activation_link = f"{get_current_site(request).domain}{reverse('account:activate', args=[token])}"
    subject = "Welcome to Sahara - Please Activate Your Account"
    
    html_message = render_to_string('welcome_email.html', {
        'user': user,
        'activation_link': activation_link,
    })
    plain_message = strip_tags(html_message)
    
    send_mail(
        subject,
        plain_message,
        settings.DEFAULT_FROM_EMAIL,
        [user.email],
        html_message=html_message,
    )
