from functools import wraps
from flask import flash, redirect, url_for
from flask_login import current_user

def active_user_required(f):
    """Decorator to ensure the current user is logged in and active."""
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if not current_user.is_authenticated:
            return redirect(url_for('auth.login'))
        if not current_user.is_active:
            flash('Your account is not active. Please contact an administrator.', 'warning')
            return redirect(url_for('main.index'))
        return f(*args, **kwargs)
    return decorated_function
