local r=(require(script.Parent.loader)).load(script)local Q=r("\077\097\105\100")local t=r("\086\097\108\117\101\079\098\106\101\099\116")local x=r("\077\097\116\101\114\105\097\108\066\117\116\116\111\110")local w=r("\084\101\114\114\097\105\110\077\097\116\101\114\105\097\108\076\105\115\116")local E=r("\066\097\115\105\099\080\097\110\101")local k=setmetatable({},E)k.ClassName="\077\097\116\101\114\105\097\108\076\105\115\116"k.__index=k function k.new(r,Q)local I=setmetatable(E.new(Q),k)I._serviceBag=assert(r,"\078\111 \115\101\114\118\105\099\101\066\097\103")I.SelectedMaterial=I._maid:Add(t.new())I._materialToButton={}for r,Q in pairs(w)do local t=x.new(I._serviceBag,Q)I:_addButton(t)end I._maid:GiveTask(I.SelectedMaterial.Changed:Connect(function(r,Q)if r then local Q=I._materialToButton[r]if Q then Q.Selected.Value=true end end if Q then local r=I._materialToButton[Q]if r then r.Selected.Value=false end end end))I.SelectedMaterial.Value=Enum.Material.Grass return I end function k._addButton(t,r)t._materialToButton[r:GetMaterial()]=r local x=Q.new()x:GiveTask(r)x:GiveTask(r.Activated:Connect(function()t.SelectedMaterial.Value=r:GetMaterial()end))r.Gui.Parent=t.Gui t._maid:GiveTask(x)end return k
--[=[
	@class MaterialList
]=]

local require = require(script.Parent.loader).load(script)

local Maid = require("Maid")
local ValueObject = require("ValueObject")
local MaterialButton = require("MaterialButton")
local TerrainMaterialList = require("TerrainMaterialList")
local BasicPane = require("BasicPane")

local MaterialList = setmetatable({}, BasicPane)
MaterialList.ClassName = "MaterialList"
MaterialList.__index = MaterialList

function MaterialList.new(serviceBag, gui)
	local self = setmetatable(BasicPane.new(gui), MaterialList)

	self._serviceBag = assert(serviceBag, "No serviceBag")

	self.SelectedMaterial = self._maid:Add(ValueObject.new())

	self._materialToButton = {}
	for _, materialData in pairs(TerrainMaterialList) do
		local button = MaterialButton.new(self._serviceBag, materialData)
		self:_addButton(button)
	end

	self._maid:GiveTask(self.SelectedMaterial.Changed:Connect(function(newValue, oldValue)
		if newValue then
			local newButton = self._materialToButton[newValue]
			if newButton then
				newButton.Selected.Value = true
			end
		end

		if oldValue then
			local oldButton = self._materialToButton[oldValue]
			if oldButton then
				oldButton.Selected.Value = false
			end
		end
	end))

	self.SelectedMaterial.Value = Enum.Material.Grass

	return self
end

function MaterialList:_addButton(materialButton)
	self._materialToButton[materialButton:GetMaterial()] = materialButton

	local maid = Maid.new()
	maid:GiveTask(materialButton)

	maid:GiveTask(materialButton.Activated:Connect(function()
		self.SelectedMaterial.Value = materialButton:GetMaterial()
	end))
	materialButton.Gui.Parent = self.Gui

	self._maid:GiveTask(maid)
end

return MaterialList