#!/usr/bi/python3
import libtmux
import settings
import libtmux.constants

#<img src="{{ url_for('static', filename='logo.png') }}" alt="Terra-Dash">

def launchserver(lpane: libtmux.Pane):
    lpane.send_keys(settings.RUN_SERVER_COMMAND)
    lpane.enter()
    lpane.send_keys(settings.LAUNCH_WORLD)
    lpane.send_keys(settings.MAX_PLAYERS)
    lpane.send_keys(settings.PORT)
    lpane.send_keys(settings.FORWARD_PORT)
    lpane.send_keys(settings.PASSWORD)


if __name__ == "__main__":
    try:
        server = libtmux.Server()
        session = server.new_session("terradash", start_directory=settings.SERVER_PATH)

        window = session.active_window
        rpane = window.active_pane
        lpane = window.split(
            direction=libtmux.constants.PaneDirection.Right,
            start_directory=settings.path,
        )

        rpane.send_keys("clear")
        lpane.send_keys("clear")

        launchserver(rpane)
        lpane.send_keys("python3 app.py")

        server.attach_session("terradash")

    except Exception as e:
        print(f"Error: {e}")
