import urllib.request

try:
    r = urllib.request.urlopen('http://localhost/Procurement/dashboard/')
    c = r.read()
    html = c.decode('utf-8')
    print(f"Status: {r.status}")
    print(f"Content length: {len(c)} bytes")
    print(f"Has Chart.js: {'chart.js' in html.lower()}")
    print(f"Has sidebar: {'sidebar' in html}")
    print(f"Has KPI cards: {'kpi-card' in html}")
    print(f"Has all sections: {'sec-resumen' in html and 'sec-tiempos' in html and 'sec-proveedores' in html and 'sec-alertas' in html}")
    
    # Check for PHP errors
    if 'Fatal error' in html or 'Parse error' in html or 'Warning:' in html:
        print("\n!!! PHP ERRORS DETECTED !!!")
        for line in html.split('\n'):
            if 'error' in line.lower() or 'Warning' in line:
                print(f"  {line.strip()[:200]}")
    else:
        print("No PHP errors detected")
    
    # Check for actual data values
    if 'Lead Time' in html:
        print("KPI data rendered correctly")
    
    # Check presence of key data tables
    print(f"Has provider scorecard: {'proveedorScore' in html or 'score_riesgo' in html}")
    print(f"Has anomaly alerts: {'anomalia' in html or 'alerta' in html}")
    
except Exception as e:
    print(f"ERROR: {e}")
