from django.shortcuts import render
from datetime import datetime, timedelta

def index(request):
    city = request.GET.get('city', 'London')
    
    # High-quality demo data
    current_weather = {
        'city': city,
        'temp': 22,
        'condition': 'Partly Cloudy',
        'icon': '⛅',
        'high': 24,
        'low': 16,
        'humidity': 64,
        'wind_speed': 12,
        'feels_like': 21,
        'uv_index': 4,
        'visibility': 10,
        'pressure': 1012,
        'updated_at': datetime.now().strftime("%H:%M")
    }
    
    hourly_forecast = []
    start_time = datetime.now()
    for i in range(12):
        time = (start_time + timedelta(hours=i)).strftime("%H:00")
        temp = 22 - (i % 3)
        hourly_forecast.append({
            'time': 'Now' if i == 0 else time,
            'temp': temp,
            'icon': '☀️' if temp > 20 else '⛅'
        })
        
    daily_forecast = []
    days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    today_idx = datetime.now().weekday()
    for i in range(7):
        day_name = days[(today_idx + i) % 7]
        daily_forecast.append({
            'day': 'Today' if i == 0 else day_name,
            'high': 24 - i,
            'low': 16 - (i % 2),
            'condition': 'Sunny' if i < 3 else 'Cloudy',
            'icon': '☀️' if i < 3 else '☁️'
        })
        
    context = {
        'current': current_weather,
        'hourly': hourly_forecast,
        'daily': daily_forecast,
    }
    return render(request, 'core/index.html', context)