local r=(require(script.Parent.loader)).load(script)local Q=game:GetService("\084\101\120\116\083\101\114\118\105\099\101")local t=r("\066\097\115\105\099\080\097\110\101")local x=r("\083\105\103\110\097\108")local w=r("\080\108\117\103\105\110\084\101\109\112\108\097\116\101\080\114\111\118\105\100\101\114")local E={}E.ClassName="\077\097\116\101\114\105\097\108\066\117\116\116\111\110"E.__index=E function E.new(r,Q)local k=setmetatable(t.new((r:GetService(w)):Clone("\077\097\116\101\114\105\097\108\066\117\116\116\111\110\084\101\109\112\108\097\116\101")),E)k._serviceBag=assert(r,"\078\111 \115\101\114\118\105\099\101\066\097\103")k.Activated=x.new()k._maid:GiveTask(k.Gui.MouseButton1Click:Connect(function()k.Activated:Fire()end))k.Selected=Instance.new("\066\111\111\108\086\097\108\117\101")k.Selected.Value=false k._maid:GiveTask(k.Selected.Changed:Connect(function()k:_updateHighlight()end))k:_updateHighlight()k._toolTip=k.Gui.ToolTip k._maid:GiveTask(k.Gui.MouseEnter:Connect(function()k._toolTip.Visible=true end))k._maid:GiveTask(k.Gui.MouseLeave:Connect(function()k._toolTip.Visible=false end))k._data=Q or error("\078\111 \109\097\116\101\114\105\097\108 \100\097\116\097")k:SetImage(k._data.image)k:SetToolTip(k._data.text)return k end function E.GetMaterial(r)return r._data.enum end function E.SetToolTip(t,r)local x=t._toolTip.TextLabel x.Text=r local w=Q:GetTextSize(r,x.TextSize,x.Font,Vector2.new(1000000.0,1000000.0))t._toolTip.Size=UDim2.new(UDim.new(0,30+w.x),t._toolTip.Size.Y)end function E.SetImage(Q,r)Q.Gui.Image=r end function E._updateHighlight(r)if r.Selected.Value then r.Gui.BackgroundTransparency=0 else r.Gui.BackgroundTransparency=1 end end function E.Destroy(r)r._maid:DoCleaning()end return E
--[=[
	@class MaterialButton
]=]

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

local TextService = game:GetService("TextService")

local BasicPane = require("BasicPane")
local Signal = require("Signal")
local PluginTemplateProvider = require("PluginTemplateProvider")

local MaterialButton = {}
MaterialButton.ClassName = "MaterialButton"
MaterialButton.__index = MaterialButton

function MaterialButton.new(serviceBag, data)
	local self = setmetatable(BasicPane.new(serviceBag:GetService(PluginTemplateProvider):Clone("MaterialButtonTemplate")), MaterialButton)

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

	-- handle activation
	self.Activated = Signal.new()
	self._maid:GiveTask(self.Gui.MouseButton1Click:Connect(function()
		self.Activated:Fire()
	end))

	-- setup highlighting
	self.Selected = Instance.new("BoolValue")
	self.Selected.Value = false
	self._maid:GiveTask(self.Selected.Changed:Connect(function()
		self:_updateHighlight()
	end))
	self:_updateHighlight()

	-- init tooltip
	self._toolTip = self.Gui.ToolTip
	self._maid:GiveTask(self.Gui.MouseEnter:Connect(function()
		self._toolTip.Visible = true
	end))
	self._maid:GiveTask(self.Gui.MouseLeave:Connect(function()
		self._toolTip.Visible = false
	end))

	-- setup data
	self._data = data or error("No material data")
	self:SetImage(self._data.image)
	self:SetToolTip(self._data.text)

	return self
end

function MaterialButton:GetMaterial()
	return self._data.enum
end

function MaterialButton:SetToolTip(text)
	local textLabel = self._toolTip.TextLabel
	textLabel.Text = text

	local size = TextService:GetTextSize(text, textLabel.TextSize, textLabel.Font, Vector2.new(1e6, 1e6))
	self._toolTip.Size = UDim2.new(UDim.new(0, 30 + size.x), self._toolTip.Size.Y)
end

function MaterialButton:SetImage(image)
	self.Gui.Image = image
end

function MaterialButton:_updateHighlight()
	if self.Selected.Value then
		self.Gui.BackgroundTransparency = 0
	else
		self.Gui.BackgroundTransparency = 1
	end
end

function MaterialButton:Destroy()
	self._maid:DoCleaning()
end

return MaterialButton