import tkinter as tk
import tkinter.font as tk_font
from tkinter import ttk

from .. import display



info_text = """# Marble Madness

Let's face it. You're a marble. How did you get like this?
For reasons unknown, you have been transformed to this
state by the good King Gargrenought, who has recently
decided to be evil.

Fortunately, the spell the King used backfired after hitting
you, so he is now a marble as well—just bigger. Your
goal is to seek revenge for this nefarious deed. However,
you must battle your way through the King's palace for the
final showdown . . .

    1:  Train in the King's garden.
    2:  Enter the palace.
    3:  Fight your way to the King.
    4:  Destroy him!


# Controls

The primary controls are by the arrow keys:

    LEFT     rotate toward left
    RIGHT   rotate toward right
    UP         rotate toward top
    DOWN   rotate toward bottom


# Credits

This was programmed entirely by Agatha Mallett, and uses
free or bespoke assets. See the readme for more details.
Licensed under the MIT License."""

def main_gui():
	window = ttk.Frame( display.tkroot, padding=5 )
	window.grid()

	text = tk.Text( window, width=47,height=35 )
	text.grid( column=0, row=0 )

	font_default = tk_font.Font( family="TkDefaultFont", size=12 )
	font_title   = tk_font.Font( family="TkHeadingFont", size=16, weight="bold" )

	def add( data:str, style:str|None=None ):
		if style:
			start = text.index("end-1c")
			text.insert( "end", data )
			end   = text.index("end-1c")
			text.tag_add( style, start,end )
		else:
			text.insert( "end", data )

	#add("Hello")
	#add("World")
	#add("Title","styletitle")
	#add("newline\nhere")
	#add("newline\nhere","styletitle")
	for line in info_text.split("\n"):
		if line.startswith("# "):
			add( line[2:]+"\n", "styletitle" )
		else:
			add( line+"\n" )

	text.configure( font = font_default )
	text.tag_configure( "styletitle", relief="raised", font=font_title )

	text.config( state=tk.DISABLED )

	display.tk_main(window.destroy)
