import sys
import cv2 as cv
from combined_user_interface import PrimaryOverlay
from equipment import Equipment
from crops import Crops
from farm import Farm
from magic import Magic
from craft import Craft
from mine import Mine


def run():
    overlay = PrimaryOverlay()

    while True:
        if overlay.run_mode == 'stopped':
            overlay.update_status_label("stopped")
            overlay.run_mode = 'init'
            continue
        elif overlay.run_mode == 'started':
            cv.waitKey(1000)
            pass
        elif overlay.run_mode == 'init':
            cv.waitKey(1)
            continue
        elif overlay.run_mode == 'paused':
            continue
        elif overlay.run_mode == 'finished':
            overlay.update_status_label("finished")
            overlay.run_mode = 'init'
            continue
        elif overlay.run_mode == 'quit':
            overlay.destroy()
            return
        else:
            break

        if overlay.rb_int.get() == 1:
            equip = Equipment(overlay)
            equip.execute_main_loop()
        elif overlay.rb_int.get() == 2:
            crops = Crops(overlay)
            crops.execute_main_loop()
        elif overlay.rb_int.get() == 3:
            farm = Farm(overlay)
            farm.execute_main_loop()
        elif overlay.rb_int.get() == 4:
            magic = Magic(overlay)
            magic.execute_main_loop()
        elif overlay.rb_int.get() == 5:
            craft = Craft(overlay)
            craft.execute_main_loop()
        elif overlay.rb_int.get() == 6:
            mine = Mine(overlay)
            mine.execute_main_loop()


if __name__ == "__main__":
    run()
    sys.exit()
