from django.shortcuts import render
from django.conf import settings
from bazi.models import Person
# from django.contrib.auth import authenticate, login
# from django.shortcuts import render, redirect
# from .forms import RegistrationForm
# from .visitor import utils
# from liuyao.models import liuyao

def index(request):
    """
    View function for the home page of the site.
    """
    # Check if user is authenticated and has a Bazi record
    if request.user.is_authenticated:
        try:
            bazi_person = Person.objects.get(created_by=request.user, owner=True)
            print(bazi_person.bazi_result)
            return render(request, 'index_personal.html', {'bazi_person': bazi_person})
        except Person.DoesNotExist:
            pass
    
    # Get services for the homepage
    services = [
        {
            'name': '六爻占卜',
            'description': '易经六爻预测是中国传统预测学的主要方法之一，通过对卦象的分析，预测未来事态的发展。',
            'link': 'liuyao:liuyao-entry'
        },
        {
            'name': '八字命理',
            'description': '八字命理是以一个人出生的年、月、日、时四柱干支为基础，结合阴阳五行生克制化分析人生命运的方法。',
            'link': 'bazi:calculate_chart'
        },
        {
            'name': '通书万年历',
            'description': '通书万年历是传统历法的重要工具，提供农历、节气、吉凶宜忌等信息，方便查询日期信息。',
            'link': 'tongshu:current_month'
        }
    ]
    
    # Render the HTML template index.html with the data
    return render(request, 'index.html', {'services': services})

def privacy_policy(request):
    """View for the privacy policy page."""
    context = {
        'site_title': getattr(settings, 'SITE_TITLE', '贵人'),
        'site_domain': getattr(settings, 'SITE_DOMAIN', request.get_host()),
        'contact_email': getattr(settings, 'CONTACT_EMAIL', 'contact@guiren.app')
    }
    return render(request, 'privacy_policy.html', context)