#!/usr/bin/env python3
"""View current Tier 1 leads with filtering"""
import json
from pathlib import Path

STATE_FILE = Path(__file__).parent / "state" / "tier1-state.json"

if STATE_FILE.exists():
    state = json.loads(STATE_FILE.read_text())
    leads = state.get('tier1_leads', [])
    
    print(f"\n{'='*70}")
    print(f"TIER 1 LEADS - Top {len(leads)}")
    print(f"{'='*70}\n")
    
    if not leads:
        print("No Tier 1 leads scored yet. Waiting for JAE v5 to process leads...")
    else:
        print(f"{'Rank':<5} {'Score':<6} {'Temp':<6} {'Units':<8} {'Budget':<8} {'Title'}")
        print("-" * 70)
        
        for i, lead in enumerate(leads[:20], 1):  # Show top 20
            score = lead.get('score', 0)
            temp = lead.get('temp', '?')
            units = str(lead.get('units', '?'))
            budget = '✓' if lead.get('budget_pdf') else '✗'
            title = lead.get('title', 'Unknown')[:40]
            
            print(f"{i:<5} {score:<6} {temp:<6} {units:<8} {budget:<8} {title}")
        
        if len(leads) > 20:
            print(f"\n... and {len(leads)-20} more")
        
        print(f"\n{'='*70}")
        print(f"Scoring Criteria:")
        print(f"  • Temperature: HOT=3pts, WARM=2pts, COLD=0pts")
        print(f"  • Units: 150-400=+4pts, 100-150/400-500=+3pts, etc.")
        print(f"  • Budget PDF: Found=+2pts, Mentioned=+1pts")
        print(f"  • Website: Yes=+1pt")
        print(f"  • Minimum score for Tier 1: 6/10")
        print(f"{'='*70}\n")
else:
    print("No Tier 1 state file found. Run tier1-scorer.py first.")
