local druid = require("druid.druid")


local function create_button(self, index)
	local cloned = gui.clone_tree(self.prefab)
	local root = cloned["prefab_button/button"]
	self.grid:add(root)
	gui.set_enabled(root, true)

	local button = self.druid:new_button(root, function()
		print("Created button with timer delay:", index)
	end)
	-- Override to check calls, don't do it in production ;)
	button.on_late_init = function()
		print("Late init button check", index)
	end

	print("Button created, is input inited now?", self.druid.input_inited)
end


function init(self)
	self.druid = druid.new(self)

	self.prefab = gui.get_node("prefab_button/button")
	gui.set_enabled(self.prefab, false)

	self.grid = self.druid:new_static_grid("grid", self.prefab, 1)

	create_button(self, 0)
	for index = 1, 4 do
		timer.delay(index, false, function()
			create_button(self, index)
		end)
	end
end


function final(self)
	self.druid:final()
end


function on_input(self, action_id, action)
	return self.druid:on_input(action_id, action)
end
