"""__main__.py"""

# Standard Library
from pathlib import Path

# Local
from .api import is_file, list_input_files, process_a_file, select_file
from .constants import LANGUAGES


def cli_select_files():
    """Loops until it finds a valid input_file"""
    print("Select data file:")
    in_file = None
    level = Path()
    while not in_file:
        files = list_input_files(level)
        for n, file in enumerate(files):
            print(f"{n+1} - {file}")
        s = None
        while not s or not s.isnumeric() or not 1 <= int(s) <= len(files):
            s = input(f"Please select the file [1-{len(files)}]: ")
        selected = files[int(s) - 1]
        if is_file(selected):
            in_file = selected
        else:
            level = selected
    input_file = select_file(in_file)
    return input_file


def cli_select_language():
    """Selects a language for the trasnlatatio"""
    print("Select a language:")
    for language_id, language in LANGUAGES.LanguageNames.items():
        print(f"{language_id} - {language}")
    s = None
    while not s or s not in LANGUAGES.AvailableLanguages:
        s = input(f"Please select the language {LANGUAGES.AvailableLanguages}: ")
    return s


def main():
    """CLI interface for the module"""
    while True:
        input_file = cli_select_files()
        language_id = cli_select_language()
        print(f"processing file {input_file.input_file} with language {language_id}")
        process_a_file(input_file, language_id)


if __name__ == "__main__":
    main()
