# LIBRARIES
import random
import os
import time

#PROGRAM COLORS
original_print = print
original_input = input
GREEN = "\033[92m"
RESET = "\033[0m"
def print(*args, **kwargs):
    original_print(f"{GREEN}", end="")
    original_print(*args, **kwargs)
    original_print(f"{RESET}", end="")
def input(prompt=""):
    return original_input(f"{GREEN}{prompt}{RESET}")

def clear_terminal():
    os.system('cls' if os.name == 'nt' else 'clear')

#MENU
def menu():
    while True:
        clear_terminal()
        print("\n~ My Virtual Oracle - Demo ~")
        print("By Nikodemus of Psykeon\n")

        print("1. Virtual Tarot Deck")
        print("2. Virtual Rune Set")

        print("\nX. Quit\n")
        
        choice = input("Select an option (1-2, X): ").strip()
        if choice == "1":
            tarot()
        elif choice == "2":
            runes()     
        elif choice in ['X', 'x']:
            print("\nThank you for consulting My Virtual Oracle - Demo.")
            time.sleep(3)
            exit()
        else:
            print("Invalid selection. Please choose a valid option.")

#TAROT DECK
def tarot():
    tarot_deck = [
        "0 - The Fool", "I - The Magician", "II - The High Priestess", "III - The Empress", "IV - The Emperor",
        "V - The Hierophant", "VI - The Lovers", "VII - The Chariot", "VIII - Strength", "IX - The Hermit",
        "X - Wheel of Fortune", "XI - Justice", "XII - The Hanged Man", "XIII - Death", "XIV - Temperance",
        "XV - The Devil", "XVI - The Tower", "XVII - The Star", "XVIII - The Moon", "XIX - The Sun", "XX - Judgement",
        "XXI - The World", "Ace of Cups", "Two of Cups", "Three of Cups", "Four of Cups", 
        "Five of Cups", "Six of Cups", "Seven of Cups", "Eight of Cups", "Nine of Cups", "Ten of Cups", "Page of Cups", "Knight of Cups", 
        "Queen of Cups", "King of Cups", "Ace of Pentacles", "Two of Pentacles", "Three of Pentacles", "Four of Pentacles", "Five of Pentacles", 
        "Six of Pentacles", "Seven of Pentacles", "Eight of Pentacles", "Nine of Pentacles", "Ten of Pentacles", "Page of Pentacles", 
        "Knight of Pentacles", "Queen of Pentacles", "King of Pentacles", "Ace of Swords", "Two of Swords", "Three of Swords", "Four of Swords", 
        "Five of Swords", "Six of Swords", "Seven of Swords", "Eight of Swords", "Nine of Swords", "Ten of Swords", "Page of Swords", 
        "Knight of Swords", "Queen of Swords", "King of Swords", "Ace of Wands", "Two of Wands", "Three of Wands", "Four of Wands", 
        "Five of Wands", "Six of Wands", "Seven of Wands", "Eight of Wands", "Nine of Wands", "Ten of Wands", "Page of Wands", 
        "Knight of Wands", "Queen of Wands", "King of Wands"
    ]

    def draw_card(available_cards, use_reversals):
        card = random.choice(available_cards)
        if use_reversals and random.choice([True, False]):
            return card + " (Reversed)"
        return card

    print("\nWelcome to the Virtual Tarot Deck.\n")
    use_reversals = input("Do you want to use reversals? (Y/N): ").strip().upper() == "Y"
    unlimited_draws = input("Do you want to draw unlimited cards? (Y/N): ").strip().upper() == "Y"
    available_cards = tarot_deck[:]
    print("\nPress [Enter] to draw a card, [R] to reset the deck, [M] to return to the menu.\n")

    while True:
        command = input().strip().upper()
        if command == 'R':
            return tarot()
        elif command == "M":
            menu()
        elif command == '':
            if not unlimited_draws and not available_cards:
                message = "No More Cards to Draw"
                frame_width = len(message) + 2
                print("+" + "-" * frame_width + "+")
                print(f"| {message} |")
                print("+" + "-" * frame_width + "+")
                continue
            if unlimited_draws:
                card = draw_card(available_cards, use_reversals)
            else:
                card = draw_card(available_cards, use_reversals)
                available_cards.remove(card.split(" (")[0])
            frame_width = len(card) + 2
            print("+" + "-" * frame_width + "+")
            print(f"| {card} |")
            print("+" + "-" * frame_width + "+")
        else:
            print("Invalid command. Please press [Enter] to draw a card, [R] to reset the deck, [M] to return to the menu.")

#RUNES SET
def runes():
    runes_set = [
        "ᚠ - Fehu", "ᚢ - Uruz", "ᚦ - Thurisaz", "ᚨ - Ansuz", "ᚱ - Raidho", "ᚲ - Kenaz", "ᚷ - Gebo", "ᚹ - Wunjo", "ᚺ - Hagalaz", 
        "ᚾ - Nauthiz", "ᛁ - Isa", "ᛃ - Jera", "ᛇ - Eihwaz", "ᛈ - Perthro", "ᛉ - Algiz", "ᛋ - Sowilo", "ᛏ - Tiwaz", "ᛒ - Berkano", 
        "ᛖ - Ehwaz", "ᛗ - Mannaz", "ᛚ - Laguz", "ᛜ - Ingwaz", "ᛞ - Dagaz", "ᛟ - Othala"
    ]
    
    def draw_rune(available_runes, use_reversals):
        rune = random.choice(available_runes)
        if use_reversals and random.choice([True, False]):
            return rune + " (Reversed)"
        return rune

    print("\nWelcome to the Virtual Runes Set.\n")
    use_reversals = input("Do you want to use reversals? (Y/N): ").strip().upper() == "Y"
    unlimited_runes = input("Do you want to draw unlimited runes? (Y/N): ").strip().upper() == "Y"
    available_runes = runes_set[:]
    print("\nPress [Enter] to draw a rune, [R] to reset the set, [M] to return to the menu.\n")

    while True:
        command = input().strip().upper()
        if command == 'R':
            return runes()
        elif command == "M":
            menu()
        elif command == '':
            if not unlimited_runes and not available_runes:
                message = "No More Runes to Draw"
                frame_width = len(message) + 2
                print("+" + "-" * frame_width + "+")
                print(f"| {message} |")
                print("+" + "-" * frame_width + "+")
                continue
            if unlimited_runes:
                rune = draw_rune(available_runes, use_reversals)
            else:
                rune = draw_rune(available_runes, use_reversals)
                available_runes.remove(rune.split(" (")[0])  
            frame_width = len(rune) + 2
            print("+" + "-" * frame_width + "+")
            print(f"| {rune} |")
            print("+" + "-" * frame_width + "+")
        else:
            print("Invalid command. Please press [Enter] to draw a rune, [R] to reset the set, [M] to return to the menu.")

menu()