import random

from kivy.config import Config
Config.set('graphics', 'resizable', True)

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button


class TileStack(GridLayout):
    TARGET = 0
    N_ROWS = 10
    N_COLS = 15

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        TARGET = random.randint(0,9) + random.randint(0,9)
        print(TARGET)
        for i in range(self.N_ROWS):
            for j in range(self.N_COLS):
                rand_int1 = random.randint(100,254)/255
                rand_int2 = random.randint(100,254)/255
                rand_int3 = random.randint(100,254)/255
                rand_int4 = random.randint(0, 9)
                my_color = (rand_int1, rand_int2, rand_int3, 1)
                my_id = f"{i}-{j}-{rand_int4}"
                self.add_widget(Utilities.NewTile(my_id, my_color, rand_int4))


class Utilities:
    @staticmethod
    def NewTile(my_id, my_color, my_value):
        button = Button(text=str(my_value))
        button.font_size = 32
        button.bold = True  # Corrected to boolean
        button.color = (0, 0, 0, 1)
        button.background_normal = ''  # Corrected background_normal
        button.background_color = my_color
        button.id = my_id
        # Bind using lambda to pass the ID correctly
        button.bind(on_press=lambda instance: Utilities.SelectedTile(button.id))
        return button

    @staticmethod
    def SelectedTile(tileid):
        print(f"selected {tileid}")


class MainLayout(BoxLayout):
    pass


class TestApp(App):
    title= "Game Test"
    def build(self):
        layout = MainLayout()
        return layout


if __name__ == '__main__':
    app = TestApp()
    app.run()

