import random
import threading
import time

from imgui_bundle import imgui, immapp

from gui_log import *


@immapp.static(idx_fortune=0)
def demo_gui():
    static = demo_gui
    fortunes = [
        "If at first you don't succeed, skydiving is not for you.",
        "You will be a winner today. Pick a fight.",
        "The world may be your oyster,"
        "The only thing constant in life is change, except for death and taxes, those are pretty constant too.",
    ]

    def add_log():
        log_level = random.choice(
            [
                hello_imgui.LogLevel.debug,
                hello_imgui.LogLevel.info,
                hello_imgui.LogLevel.warning,
                hello_imgui.LogLevel.error,
            ]
        )
        hello_imgui.log(log_level, fortunes[static.idx_fortune])
        static.idx_fortune += 1
        if static.idx_fortune >= len(fortunes):
            static.idx_fortune = 0
    imgui.separator()
    hello_imgui.log_gui()


def another_loop():
    immapp.run(demo_gui, "Log", with_markdown=True)


def main():
    threading.Thread(target=another_loop, daemon=True).start()

    while True:
        log_debug("hello")
        time.sleep(1)


if __name__ == "__main__":
    main()
