"""
Context processors for enviPy application.

Context processors automatically make variables available to all templates.
"""

from .logic import PackageManager
from django.conf import settings as s


def package_context(request):
    """
    Provides package data for the search modal which is included globally
    in framework_modern.html.

    Returns:
        dict: Context dictionary with reviewed and unreviewed packages
    """
    current_user = request.user

    reviewed_package_qs = PackageManager.get_reviewed_packages()

    unreviewed_package_qs = s.GET_PACKAGE_MODEL().objects.none()

    # Only get user-specific packages if user is authenticated
    if current_user.is_authenticated:
        unreviewed_package_qs = PackageManager.get_all_readable_packages(current_user)

    return {
        "reviewed_packages": reviewed_package_qs,
        "unreviewed_packages": unreviewed_package_qs,
    }
