MOVE_LABELS = {
    "UP": "U", # for testing, may change to actual arrows later on
    "DOWN": "D",
    "LEFT": "L",
    "RIGHT": "R",
    "A": "A",
    "B": "B",
}

BAR_X = 4
BAR_Y = 54
BAR_W = 120
BAR_H = 8

def draw_move(oled, move, x, y):

    if move == "UP":
        oled.line(x + 4, y,     x,     y + 4, 1)
        oled.line(x + 4, y,     x + 8, y + 4, 1)
        oled.line(x + 4, y,     x + 4, y + 9, 1)

    elif move == "DOWN":
        oled.line(x + 4, y + 9, x,     y + 5, 1)
        oled.line(x + 4, y + 9, x + 8, y + 5, 1)
        oled.line(x + 4, y,     x + 4, y + 9, 1)

    elif move == "LEFT":
        oled.line(x, y +4,     x +4,     y, 1)
        oled.line(x, y + 4,     x + 4, y + 8, 1)
        oled.line(x, y + 4,     x + 9, y + 4, 1)

    elif move == "RIGHT":
        oled.line(x+9, y +4,     x +5,     y, 1)
        oled.line(x + 9, y + 4,     x + 5, y + 8, 1)
        oled.line(x + 9, y + 4,     x, y + 4, 1)

    elif move == "A":
        oled.text("A", x, y)

    elif move == "B":
        oled.text("B", x, y)

def draw_game(oled, game):
    
    

    oled.fill(0)
    oled.text("STREAK:", 0, 0)
    oled.text(str(game.streak), 56, 0)

    #oled.text("MOVESET", 80, 0) # no longer needs this as taking too much space on screen

    # Starting x position and spacing
    start_x = 16
    spacing = 22
    y = 24

    for i, move in enumerate(game.sequence):

        label = MOVE_LABELS[move]
        x = start_x + i * spacing

        draw_move(oled, move, x, y)

        # Show current move
        if i == game.position and not game.success:
            oled.text("^", x, y + 12)

    if game.success:
        oled.text("SUCCESS!", 32, 52)

    elif game.failed:
        oled.text("MISS!", 44, 52)

    if game.state == "PLAYING":

        fraction = game.time_fraction()

        # Outline
        oled.rect(BAR_X, BAR_Y, BAR_W, BAR_H, 1)

        # Calculate filled width
        fill_width = int((BAR_W - 2) * fraction)


        # Draw a filled rectangle inside the border.

        oled.fill_rect(
            BAR_X + 1,
            BAR_Y + 1,
            fill_width,
            BAR_H - 2,
            1
        )

    if game.state == "FEEDBACK":

        if game.outcome == "SUCCESS":
            oled.text("SUCCESS!", 32, 44)

        else:
            oled.text("MISS!", 44, 44)

    oled.show()
    
    