# Github: https://github.com/turmanauli/Easy-Problem-Solving-Business-Framework
import os  # importing Operating System access (file/folder creation/removal)
import sys  # importing system (for input/output)
import re  # importing regular expressions
from core.business_creation import create_project_files
from core.business_management.improve_business import improve
from core.business_management.modify_project import modify
from termcolor import colored

print(colored('+-----------------------------------------------------------------------+', 'green'))
print(colored('E A S Y  P R O B L E M  S O L V I N G  B U S I N E S S  F R A M E W O R K', 'green'))
print(colored('+-----------------------------------------------------------------------+', 'green'))
print(colored('        -- Master What You Do For Others : For A Better World --\n', 'white'))

print(colored('+--------------------------------------------------------------------------+', 'white'))
print('Contrary to popular belief, doing business is something rather easy, it has')
print('positive and negative sides though, you may enjoy working for someone more,')
print('on a specific project, with specific people, or you may indeed want to start')
print('a business from scratch: a startup in order to find new ways to improve lives')
print('of other people, create jobs and generate capital for new ventures and/or to')
print('appreciate life from a different perspective...')
print(colored('+--------------------------------------------------------------------------+', 'white'))



def choose_name(sys, re, os, project_name, projects_directory_name):
    print("Please enter the name of your next business:")
    project_name = sys.stdin.readline()  # read input
    project_name = re.sub('[^0-9a-zA-Z\n\r\r\n]+', '-',
                          project_name)  # replace all non-alphanumeric characters with '-'
    project_name = project_name.replace('\n', '').replace('\r', '')  # remove last character (New Line replaced by '-')

    if os.path.isdir(projects_directory_name + "/" + project_name):
        print(colored("\nProject already exists! What you want to do next? (type the number and hit Enter)", "yellow"))
        print(colored("+------------------------------------------------------------------\n", "yellow"))
        print(colored("1)", "blue") + " Choose A Different Name")
        print(colored("2)", "blue") + " Go Home")
        choice3 = sys.stdin.readline()
        choice3 = re.sub('[^0-9]+', '', choice3)
        if choice3 == '1':
            choose_name(sys, re, os, project_name, projects_directory_name)
        elif choice3 == '2':
            initialise(sys, re, os)
    else:
        create_project_files.create_files(sys, re, os, project_name, projects_directory_name)


def initialise(sys, re, os):
    project_name = ""
    projects_directory_name = "business_projects"
    print(colored("\nWhat you want to do next? (type the number and hit Enter)", "yellow"))
    print(colored("+--------------------------------------------------------\n", "yellow"))
    print(colored("1)", "blue") + " Create A Business")
    print(colored("2)", "blue") + " Improve Your Business")
    print(colored("3)", "blue") + " Exit")
    choice = sys.stdin.readline()
    choice = re.sub('[^0-9]+', '', choice)

    if choice == '1':
        print(colored("\nWhat you want to do next? (type the number and hit Enter)", "yellow"))
        print(colored("+--------------------------------------------------------\n", "yellow"))
        print(colored("1)", "blue") + " Choose Name")
        print(colored("2)", "blue") + " Go Back")
        choice2 = sys.stdin.readline()
        choice2 = re.sub('[^0-9]+', '', choice2)
        if choice2 == '1':
            choose_name(sys, re, os, project_name, projects_directory_name)
        elif choice2 == '2':
            initialise(sys, re, os)

    elif choice == '2':
        print(colored("\nWhat you want to do next? (type the number and hit Enter)", "yellow"))
        print(colored("+--------------------------------------------------------\n", "yellow"))
        print(colored("1)", "blue") + " Select Areas To Improve")
        print(colored("2)", "blue") + " Modify The Core Project")
        print(colored("3)", "blue") + " Go Back")
        choice4 = sys.stdin.readline()
        choice4 = re.sub('[^0-9]+', '', choice4)
        if choice4 == '1':
            improve.run(os, sys, colored)
        elif choice4 == '2':
            modify.run(os, sys, colored, re)
        elif choice4 == '3':
            initialise(sys, re, os)
    elif choice == '3':
        quit()

initialise(sys, re, os)
