from django.shortcuts import render

# Mock data for the country comparison
MOCK_COUNTRY_DATA = {
    'CA': {
        'country': 'Canada',
        'avg_tuition': '$15,000 - $35,000 CAD',
        'living_costs': '$15,000 - $20,000 CAD/year',
        'post_study_visa': 'Up to 3 years (PGWP)',
        'pr_pathway': 'Strong (Express Entry, PNP)',
    },
    'AU': {
        'country': 'Australia',
        'avg_tuition': '$25,000 - $45,000 AUD',
        'living_costs': '$21,041 AUD/year (minimum)',
        'post_study_visa': '2-4 years (TGV)',
        'pr_pathway': 'Moderate (Points-based system)',
    },
    'GB': {
        'country': 'United Kingdom',
        'avg_tuition': '£15,000 - £38,000',
        'living_costs': '£12,000 - £15,000/year',
        'post_study_visa': '2 years (Graduate Route)',
        'pr_pathway': 'Limited (Skilled Worker Visa)',
    },
    'US': {
        'country': 'United States',
        'avg_tuition': '$28,000 - $55,000 USD',
        'living_costs': '$15,000 - $25,000 USD/year',
        'post_study_visa': '1-3 years (OPT)',
        'pr_pathway': 'Difficult (H-1B lottery)',
    },
    'DE': {
        'country': 'Germany',
        'avg_tuition': 'Often free at public universities',
        'living_costs': '€11,208/year (minimum)',
        'post_study_visa': '18 months (Job Seeker Visa)',
        'pr_pathway': 'Good (EU Blue Card)',
    }
}

AVAILABLE_COUNTRIES = [
    {'code': 'CA', 'name': 'Canada'},
    {'code': 'AU', 'name': 'Australia'},
    {'code': 'GB', 'name': 'United Kingdom'},
    {'code': 'US', 'name': 'United States'},
    {'code': 'DE', 'name': 'Germany'},
]

def index(request):
    comparison_results = []
    if request.method == 'POST':
        selected_countries = request.POST.getlist('countries')
        comparison_results = [MOCK_COUNTRY_DATA[code] for code in selected_countries if code in MOCK_COUNTRY_DATA]

    context = {
        'available_countries': AVAILABLE_COUNTRIES,
        'comparison_results': comparison_results,
    }
    return render(request, "core/index.html", context)