import time
import qprompt
import toml
from lang import Lang
from os import listdir
from os.path import isfile, join
from pyfiglet import Figlet


def find_langs():
    langs = ["lang/" + f for f in listdir("lang") if f[-5:] == ".toml"]
    langs_o = []
    for lang in langs:
        lang_o = Lang()
        with open(lang, encoding='utf-8') as lang_file:
            data = toml.load(lang_file)
            lang_o.load(data)
            langs_o.append(lang_o)
    return langs_o


def load_prog():
    pass


def main():
    langs = find_langs()
    if len(langs) == 0:
        qprompt.error("No languages present in lang directory!")
        exit()
    menu = qprompt.Menu()
    for lan in langs:
        menu.add(lan.id, lan.name)
    menu.add("q", "Quit")
    ch = menu.show()
    if ch == "q":
        exit()


def splash():
    fig = Figlet(font="lean")
    print(fig.renderText("STMP")[:-100])
    print("By Flevosap, [...]\n")


if __name__=="__main__":
    splash()
    main()
