from django.shortcuts import render
from signals.engine import generate_signal

def home(request):
    """
    Renders the home page with a trading signal for the active symbol.
    """
    # 1. ACTIVE SYMBOL STATE: Get symbol from URL parameter, default to BTC/USDT
    symbol = request.GET.get('symbol', 'BTC/USDT').upper()

    try:
        # 3. BACKEND INTEGRATION: Generate signal for the active symbol
        signal = generate_signal(symbol)
    except Exception as e:
        signal = f'Error: {e}'

    # A list of symbols for the dropdown selector
    available_symbols = ['BTC/USDT', 'ETH/USDT', 'XRP/USDT', 'LTC/USDT', 'ADA/USDT', 'SOL/USDT', 'DOGE/USDT']

    context = {
        'active_symbol': symbol,
        'signal': signal,
        'available_symbols': available_symbols,
    }
    return render(request, "core/index.html", context)
