from django.conf import settings
from django.templatetags.static import static

from .models import SiteSettings


def site_settings(request):
    google = settings.SOCIALACCOUNT_PROVIDERS.get('google', {}).get('APP', {})
    # Do not include a query string in canonical URLs. Prefer the configured
    # production domain so links shared by crawlers are always HTTPS.
    site_url = settings.SITE_URL or request.build_absolute_uri('/').rstrip('/')
    canonical_url = f'{site_url}{request.path}'
    return {
        'site_settings': SiteSettings.current(),
        'google_oauth_configured': bool(google.get('client_id') and google.get('secret')),
        'canonical_url': canonical_url,
        'share_image_url': f"{site_url}{static('img/vaylogo.png')}",
    }
