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