local A=script.Parent.Parent local m=require(A:WaitForChild("\076\097\122\121\076\111\097\100\101\114"))local Y=A:WaitForChild("\068\101\102\097\117\108\116\115")local x=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local a={[Enum.UserInputType.MouseButton1]=true,[Enum.UserInputType.Touch]=true}local s="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\049\053\052\048\055\056\057\050\053"local t="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\049\052\051\049\054\053\053\052\057"local I=Y:WaitForChild("\068\114\111\112\100\111\119\110\066\117\116\116\111\110")local Q={}Q.__index=Q Q.__type="\068\114\111\112\100\111\119\110"function Q.__tostring(A)return Q.__type end function Q.new(A,Y)local x=setmetatable({},Q)x._Maid=m.Utilities.Maid.new()x._ChangedBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")x._Options={}x._Selected=nil x.Button=A x.ListFrame=Y x.Changed=x._ChangedBind.Event init(x)x:Set(x._Options[1])return x end function Q.Create(A,Y)Y=Y or#A local x=I:Clone()local a=m.Constructors.List.Create(A,Y)a.Position=UDim2.new(0,0,1,0)a.Size=UDim2.new(1,0,Y,0)a.Visible=false a.Parent=x return Q.new(x,a)end function init(A)local m=A.Button local Y=A.ListFrame local function s()local A=m.AbsoluteSize local Y=A.y/A.x m.Arrow.Size=UDim2.new(Y,0,1,0)m.Option.Size=UDim2.new(1-Y,-12,1,0)end s()A._Maid:Mark((m:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(s))for m,Y in next,Y.ScrollFrame:GetChildren()do A._Options[m]=Y Y.Activated:Connect(function()A:Set(Y)end)end A._Maid:Mark(m.Activated:Connect(function()A:Show(not Y.Visible)end))A._Maid:Mark(x.InputBegan:Connect(function(x)if a[x.UserInputType]then local a=x.Position local s=Vector2.new(a.x,a.y)if Y.Visible and not(isInFrame(Y,s)or isInFrame(m,s))then A:Show(false)end end end))end function isInFrame(A,m)local Y=A.AbsolutePosition local x=A.AbsoluteSize local a=m-Y return a.x>=0 and(a.x<=x.x and(a.y>=0 and a.y<=x.y))end function Q.Set(m,A)if m._Selected~=A then m._Selected=A m._ChangedBind:Fire(A)m.Button.Option.Text=A.Label.Text end m:Show(false)end function Q.Get(A)return A._Selected end function Q.Show(m,A)m.Button.Arrow.Image=A and s or t m.ListFrame.Visible=A end function Q.Destroy(A)A._Maid:Sweep()A._Changed=nil A._Options=nil A._Selected=nil A.Button:Destroy()end return Q
--[[
Classes.Dropdown

This class creates a dropdown that the user can select a list of options from.

Constructors:
	new(frame [instance], listFrame [instance])
		>
	Create(list[] [string], max [integer])
		> Creates a dropdown from the list with a max scrolling number.

Properties:
	Frame [instance]
		> The container frame for the dropdown. Can be used for positioning and resizing.
	ListFrame [instance]
 		> The contaienr frame for the dropdown list. Parented underneath the main container frame.

Methods:
	:Set(option [instance]) [void]
		> option is a child of the ListFrame and you can set it as the selected option of the dropdown with this method
	:Get() [instance]
		> Returns the selected option frame (which is again, a child of the ListFrame)
	:Show(bool [boolean])
		> Set whether the dropdown list is visible or not.
	:Destroy() [void]
		> Destroys the RadioButtonGroup and all the events, etc that were running it.

Events:
	.Changed:Connect(function(option [instance])
		> Fired when the user selects a new option from the dropdown list.
--]]


-- CONSTANTS

local GuiLib = script.Parent.Parent
local Lazy = require(GuiLib:WaitForChild("LazyLoader"))
local Defaults = GuiLib:WaitForChild("Defaults")

local UIS = game:GetService("UserInputService")

local VALID_PRESS = {
	[Enum.UserInputType.MouseButton1] = true;
	[Enum.UserInputType.Touch] = true;
}

local ARROW_UP = "rbxassetid://5154078925"
local ARROW_DOWN = "rbxassetid://5143165549"

local DROP_BUTTON = Defaults:WaitForChild("DropdownButton")

-- Class

local DropdownClass = {}
DropdownClass.__index = DropdownClass
DropdownClass.__type = "Dropdown"

function DropdownClass:__tostring()
	return DropdownClass.__type
end

-- Public Constructors

function DropdownClass.new(button, listFrame)
	local self = setmetatable({}, DropdownClass)
	
	self._Maid = Lazy.Utilities.Maid.new()
	self._ChangedBind = Instance.new("BindableEvent")
	self._Options = {}
	self._Selected = nil
	
	self.Button = button
	self.ListFrame = listFrame
	self.Changed = self._ChangedBind.Event
	
	init(self)
	self:Set(self._Options[1])
	
	return self
end

function DropdownClass.Create(list, max)
	max = max or #list
	
	local button = DROP_BUTTON:Clone()
	local listFrame = Lazy.Constructors.List.Create(list, max)
	
	listFrame.Position = UDim2.new(0, 0, 1, 0)
	listFrame.Size = UDim2.new(1, 0, max, 0)
	listFrame.Visible = false
	listFrame.Parent = button
	
	return DropdownClass.new(button, listFrame)
end

-- Private Methods

function init(self)
	local button = self.Button
	local listFrame = self.ListFrame
	
	local function contentSizeUpdate()
		local absSize = button.AbsoluteSize
		local ratio = absSize.y / absSize.x
		
		button.Arrow.Size = UDim2.new(ratio, 0, 1, 0)
		button.Option.Size = UDim2.new(1 - ratio, -12, 1, 0)
	end
	
	contentSizeUpdate()
	self._Maid:Mark(button:GetPropertyChangedSignal("AbsoluteSize"):Connect(contentSizeUpdate))
	
	for i, optionButton in next, listFrame.ScrollFrame:GetChildren() do
		self._Options[i] = optionButton
		optionButton.Activated:Connect(function()
			self:Set(optionButton)
		end)
	end

	self._Maid:Mark(button.Activated:Connect(function()
		self:Show(not listFrame.Visible)
	end))
	
	self._Maid:Mark(UIS.InputBegan:Connect(function(input)
		if (VALID_PRESS[input.UserInputType]) then
			local p = input.Position
			local p2 = Vector2.new(p.x, p.y)
			
			if (listFrame.Visible and not (isInFrame(listFrame, p2) or isInFrame(button, p2))) then
				self:Show(false)
			end
		end
	end))
end

function isInFrame(frame, pos)
	local fPos = frame.AbsolutePosition
	local fSize = frame.AbsoluteSize
	local d = pos - fPos
	return (d.x >= 0 and d.x <= fSize.x and d.y >= 0 and d.y <= fSize.y)
end

-- Public Methods

function DropdownClass:Set(option)
	if (self._Selected ~= option) then
		self._Selected = option
		self._ChangedBind:Fire(option)
		self.Button.Option.Text = option.Label.Text
	end
	self:Show(false)
end

function DropdownClass:Get()
	return self._Selected
end

function DropdownClass:Show(bool)
	self.Button.Arrow.Image = bool and ARROW_UP or ARROW_DOWN
	self.ListFrame.Visible = bool
end

function DropdownClass:Destroy()
	self._Maid:Sweep()
	self._Changed = nil
	self._Options = nil
	self._Selected = nil
	self.Button:Destroy()
end

--

return DropdownClass