import os
import time
import webbrowser
import random
from rich.console import Console
from rich.progress import track
import pyfiglet

console = Console()

# Clear screen
def clear():
    os.system("clear")

# Matrix rain effect
def matrix_rain():
    console.print("[green]")
    for _ in range(15):
        line = "".join(random.choice("01") for _ in range(80))
        console.print(line)
        time.sleep(0.05)
    console.print()

# Hacker boot animation
def hacker_loading():
    console.print("[bold green]Booting system...[/bold green]")
    for _ in track(range(25), description="[green]Injecting packets..."):
        time.sleep(0.04)
    console.print("[bold green]ACCESS GRANTED\n")

# Fake hacking scan
def scan_effect():
    steps = [
        "Scanning ports...",
        "Bypassing firewall...",
        "Decrypting keys...",
        "Injecting payload...",
        "Establishing secure shell..."
    ]

    for step in steps:
        console.print(f"[green]{step}")
        time.sleep(0.35)

    console.print("[bold green]>> SYSTEM COMPROMISED\n")

# Big Logo
def show_logo():
    logo = pyfiglet.figlet_format("SANJJAY", font="slant")
    console.print(f"[bold green]{logo}")

    kali_text = pyfiglet.figlet_format("KALI LINUX", font="small")
    console.print(f"[green]{kali_text}")

# Typing effect
def type_writer(text, delay=0.015):
    for char in text:
        print(char, end="", flush=True)
        time.sleep(delay)
    print()

# About
def about():
    type_writer("\n[+] Name: Sanjjay")
    type_writer("[+] Web Developer | App Developer | Python Programmer")
    type_writer("[+] Building real-world projects")
    type_writer("[+] Cybersecurity Enthusiast\n")

# Skills
def skills():
    type_writer("\n[+] Python")
    type_writer("[+] JavaScript")
    type_writer("[+] Linux (Kali)")
    type_writer("[+] Web Development")
    type_writer("[+] Automation & Security Learning\n")

# Projects
def projects():
    type_writer("\n[+] Fetching repositories...")
    time.sleep(1)
    type_writer("[+] https://github.com/sanjjaystars")
    type_writer("[+] CLI Portfolio Tool")
    type_writer("[+] ERP System")
    type_writer("[+] Automation Scripts\n")

# Open links
def open_github():
    console.print("[green]Opening GitHub...[/green]")
    webbrowser.open("https://github.com/sanjjaystars")

def open_linkedin():
    console.print("[green]Opening LinkedIn...[/green]")
    webbrowser.open("https://www.linkedin.com/in/sanjjay-aroumougam-43a919382/")

# Help
def help_menu():
    console.print("""
[bold green]
Available Commands:
> help
> about
> skills
> projects
> github
> linkedin
> clear
> exit
""")

# Main
def main():
    clear()
    matrix_rain()
    hacker_loading()
    scan_effect()
    show_logo()

    console.print("[bold green]Type 'help' to see commands\n")

    while True:
        cmd = input("root@sanjjay:~$ ").strip().lower()

        if cmd == "help":
            help_menu()
        elif cmd == "about":
            about()
        elif cmd == "skills":
            skills()
        elif cmd == "projects":
            projects()
        elif cmd == "github":
            open_github()
        elif cmd == "linkedin":
            open_linkedin()
        elif cmd == "clear":
            clear()
        elif cmd == "exit":
            console.print("[red]Session terminated.")
            break
        else:
            console.print("[red]Command not found")