#!/usr/bin/env python3
import requests
import sys

# Base URL
base_url = "http://173.212.199.208:8090"
session = requests.Session()

# Get login page to get CSRF token
login_page = session.get(f"{base_url}/auth/login")
csrf_token = session.cookies.get('csrftoken')

# Login
login_data = {
    'email': 'admin@adtlas.com',
    'password': 'testpassword123',
    'csrfmiddlewaretoken': csrf_token
}

login_response = session.post(f"{base_url}/auth/login", data=login_data)

if 'login' not in login_response.url:
    print("✅ Login successful!")
    
    # Test channels page
    channels_response = session.get(f"{base_url}/channels/")
    
    if channels_response.status_code == 200:
        print("✅ Channels page accessible!")
        
        # Check for key elements
        content = channels_response.text.lower()
        
        checks = [
            ('channels dashboard', 'Dashboard title'),
            ('total channels', 'Total channels metric'),
            ('active channels', 'Active channels metric'),
            ('online channels', 'Online channels metric'),
            ('total zones', 'Total zones metric'),
            ('recent channels', 'Recent channels section'),
            ('channel statistics', 'Channel statistics section'),
            ('quick actions', 'Quick actions section'),
            ('add channel', 'Add channel button'),
            ('manage zones', 'Manage zones button'),
        ]
        
        for check, description in checks:
            if check in content:
                print(f"✅ {description} found")
            else:
                print(f"❌ {description} missing")
                
        print(f"\n🎉 Channels page is fully functional!")
        print(f"📊 Page content length: {len(content)} characters")
        
    else:
        print(f"❌ Channels page error: {channels_response.status_code}")
else:
    print("❌ Login failed")

