import typer
from rich.console import Console
from rich.panel import Panel
import webbrowser
from pathlib import Path

from .data import SUMMARY, SKILLS, PROJECTS, EXPERIENCE, CONTACT, RESUME

app = typer.Typer()
console = Console()

GREEN = "bold #00FF41"


def load_ascii():

    path = Path(__file__).parent / "ascii_logo.txt"

    if path.exists():
        return path.read_text()

    return "ABIL BIJU"


def show_welcome():

    ascii_logo = load_ascii()

    console.print(ascii_logo, style=GREEN)

    console.print(
        Panel.fit(
            SUMMARY
            + """

COMMANDS

projects
skills
resume
experience
contact
open
help
exit
""",
            style=GREEN,
        )
    )


@app.command()
def start():

    show_welcome()

    while True:

        cmd = console.input("[bold #00FF41]>> [/bold #00FF41]").strip().lower()

        if cmd == "projects":
            console.print(PROJECTS, style=GREEN)

        elif cmd == "skills":
            console.print(SKILLS, style=GREEN)

        elif cmd == "resume":
            console.print(RESUME, style=GREEN)

        elif cmd == "experience":
            console.print(EXPERIENCE, style=GREEN)

        elif cmd == "contact":
            console.print(CONTACT, style=GREEN)

        elif cmd == "open":
            webbrowser.open("https://abilbiju.dev")

        elif cmd == "help":

            console.print(
                """
COMMANDS

projects
skills
resume
experience
contact
open
exit
""",
                style=GREEN,
            )

        elif cmd == "exit":
            break

        else:
            console.print("Unknown command", style="bold red")


if __name__ == "__main__":
    app()