"""Aditya's resume as a Python package with beautiful TUI."""
import re

resume = {
    "name": "Aditya Kumar",
    "title": "Software Developer",
    "contact": {
        "email": "kradi2098@gmail.com",
        "github": "github.com/GxAditya",
        "linkedin": "linkedin.com/in/aditya-kumar-3721012aa/",
        "peerlist": "https://peerlist.io/gxaditya",
        "youtube": "https://www.youtube.com/@GxAditya-Dev"
    },
    "summary": "Backend and AI Agents developer with expertise in building scalable and intelligent applications.",
    "skills": [
        "Java", "CrewAI", "FastAPI", "Python", "Springboot", "AWS",
        "Langchain", "Langgraph", "Google ADK", "Langchain4j", "MySQL",
        "PostgreSQL", "MongoDB", "Supabase", "Netlify", "Vercel"
    ],
    "opensource": [
        "https://github.com/LeeFred3042U/kitcat/pull/217",
        "https://github.com/aayush-1709/Drive-Detect/pull/20",
        "https://github.com/prasoonk1204/BreatheEasy/pull/104",
        "https://github.com/openfoodfacts/openfoodfacts-explorer/pull/1021"
    ],
    "experience": [{
        "company": "Infosys Springboard",
        "position": "Student Intern",
        "duration": "August 2025 - October 2025",
        "description": "Built end-to-end apps"
    }],
    "education": [{
        "institution": "Shri Shankaracharya Technical Campus , Bhilai",
        "degree": "Bachelor of Technology",
        "field": "Computer Science",
        "year": "2022-2026"
    }]
}

# ANSI colors
class C:
    r = '\033[0m'
    b = '\033[1m'
    d = '\033[2m'
    c = '\033[36m'
    g = '\033[32m'
    y = '\033[33m'
    m = '\033[35m'
    bl = '\033[34m'
    w = '\033[37m'
    re = '\033[31m'

BOX = {
    'h': '─', 'v': '│', 'tl': '┌', 'tr': '┐',
    'bl': '└', 'br': '┘', 'ml': '├', 'mr': '┤'
}
W = 62
ANSI_RE = re.compile(r'\033\[\d+m')

def vis_len(s):
    """Get visible length by stripping ANSI codes."""
    return len(ANSI_RE.sub('', s))

def pad_vis(s, width):
    """Pad string to visible width."""
    visible_len = vis_len(s)
    return s + ' ' * max(0, width - visible_len)

def ln(left, content, right, color=C.c):
    """Print a box line."""
    print(f"{color}{left}{C.r}{pad_vis(content, W)}{color}{right}{C.r}")

def center(text, width):
    """Center text accounting for ANSI codes."""
    visible_len = vis_len(text)
    pad = max(0, width - visible_len)
    left = pad // 2
    return ' ' * left + text + ' ' * (pad - left)

def print_resume():
    """Print a beautiful TUI resume."""
    print()
    ln(BOX['tl'], BOX['h'] * W, BOX['tr'])
    ln(BOX['v'], center('', W), BOX['v'])
    ln(BOX['v'], center(f"{C.b}{C.w}{resume['name']}{C.r}", W), BOX['v'])
    ln(BOX['v'], center(f"{C.d}{resume['title']}{C.r}", W), BOX['v'])
    ln(BOX['v'], center('', W), BOX['v'])
    ln(BOX['ml'], BOX['h'] * W, BOX['mr'])
    
    ln(BOX['v'], f"  {C.y}📧  Email:  {C.r}{resume['contact']['email']}", BOX['v'])
    ln(BOX['v'], f"  {C.g}🐙  GitHub: {C.r}{resume['contact']['github']}", BOX['v'])
    ln(BOX['v'], f"  {C.bl}💼  LinkedIn: {C.r}{resume['contact']['linkedin']}", BOX['v'])
    ln(BOX['v'], f"  {C.m}🚀  Peerlist: {C.r}{resume['contact']['peerlist'].replace('https://', '')}", BOX['v'])
    ln(BOX['v'], f"  {C.re}📺  YouTube: {C.r}{resume['contact']['youtube'].replace('https://', '')}", BOX['v'])
    ln(BOX['ml'], BOX['h'] * W, BOX['mr'])
    
    ln(BOX['v'], f"  {C.b}{C.y}📝  Summary{C.r}", BOX['v'])
    ln(BOX['v'], f"     {resume['summary'][:W-7]}", BOX['v'])
    ln(BOX['v'], '', BOX['v'])
    
    ln(BOX['v'], f"  {C.b}{C.g}🛠️  Skills{C.r}", BOX['v'])
    colors = [C.c, C.g, C.y, C.m, C.bl, C.re]
    line = '     '
    for i, skill in enumerate(resume['skills']):
        cs = f"{colors[i % 6]}{skill}{C.r}"
        next_len = vis_len(line) + vis_len(cs) + (3 if i > 0 else 0)
        if next_len > W:
            ln(BOX['v'], line, BOX['v'])
            line = '     ' + cs
        else:
            line += (' • ' if i > 0 else '') + cs
    if line.strip():
        ln(BOX['v'], line, BOX['v'])
    ln(BOX['v'], '', BOX['v'])
    
    ln(BOX['v'], f"  {C.b}{C.m}🌟  Open Source{C.r}", BOX['v'])
    for url in resume['opensource']:
        short = url.replace('https://github.com/', '').replace('/pull/', '#')
        ln(BOX['v'], f"     {C.g}✓{C.r} {C.d}{short[:W-8]}{C.r}", BOX['v'])
    ln(BOX['v'], '', BOX['v'])
    
    ln(BOX['v'], f"  {C.b}{C.bl}💼  Experience{C.r}", BOX['v'])
    for exp in resume['experience']:
        ln(BOX['v'], f"     {C.b}{C.w}{exp['position']}{C.r} {C.c}@{C.r} {C.y}{exp['company']}{C.r}", BOX['v'])
        ln(BOX['v'], f"     {C.d}{exp['duration']}{C.r}", BOX['v'])
        ln(BOX['v'], f"     {exp['description']}", BOX['v'])
    ln(BOX['v'], '', BOX['v'])
    
    ln(BOX['v'], f"  {C.b}{C.y}🎓  Education{C.r}", BOX['v'])
    for edu in resume['education']:
        ln(BOX['v'], f"     {C.b}{C.w}{edu['degree']} in {edu['field']}{C.r}", BOX['v'])
        ln(BOX['v'], f"     {C.d}{edu['institution']}{C.r}", BOX['v'])
        ln(BOX['v'], f"     {C.y}{edu['year']}{C.r}", BOX['v'])
    
    ln(BOX['bl'], BOX['h'] * W, BOX['br'])
    print()
    print(f"  {C.d}Run {C.c}pip install kaditya{C.r}{C.d} && {C.c}kaditya{C.r}{C.d} to see this again!{C.r}")
    print()
