local g="\078\101\120\117\115\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101\067\111\110\115\116\114\097\105\110\116"local A=(require(script.Parent.Parent.Parent.Parent:WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107\080\114\111\106\101\099\116"))):GetContext(script)local I=A:GetResource("\066\097\115\101\046\078\101\120\117\115\067\111\110\116\097\105\110\101\114")local O=A:GetResource("\078\101\120\117\115\073\110\115\116\097\110\099\101\046\069\118\101\110\116\046\078\101\120\117\115\069\118\101\110\116\067\114\101\097\116\111\114")local Y=I:Extend()Y:SetClassName(g)A:SetContextResource(Y)function Y.__new(A)A:InitializeSuper()A.Name=g A.__ListFrames={}A.ListFrameAdded=O:CreateEvent()A.ListFrameRemoved=O:CreateEvent()A.ListFramesUpdated=O:CreateEvent()end function Y.ContainsListFrame(A,g)for A,I in pairs(A.__ListFrames)do if I==g then return true end end return false end function Y.GetListFrames(g)local A={}for g,I in pairs(g.__ListFrames)do A[g]=I end return A end function Y.GetAllListFrames(A,g)local I={}local function O(A)if not A:IsA("\078\101\120\117\115\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101")then return end if A.Visible then table.insert(I,A)if g~=true or A.Expanded then for g,A in pairs((A:GetCollapsableContainer()):GetChildren())do O(A)end end end end for g,A in pairs(A.__ListFrames)do O(A)end return I end function Y.SortListFrames(A,g)table.sort(A.__ListFrames,g)A.ListFramesUpdated:Fire()end function Y.AddListFrame(I,g,A)if I:ContainsListFrame(g)then return end if A then table.insert(I.__ListFrames,A,g)else table.insert(I.__ListFrames,g)end I.ListFrameAdded:Fire(g)I.ListFramesUpdated:Fire()end function Y.RemoveListFrame(A,g)local I for A,O in pairs(A.__ListFrames)do if O==g then I=A break end end if I then table.remove(A.__ListFrames,I)A.ListFrameRemoved:Fire(g)A.ListFramesUpdated:Fire()end end function Y.ClearListFrames(g)local A=g:GetListFrames()g.__ListFrames={}for A,I in pairs(A)do g.ListFrameRemoved:Fire(I)end g.ListFramesUpdated:Fire()end return Y
--[[
TheNexusAvenger

Abstract class for a constraint on list frames.
--]]

local CLASS_NAME = "NexusCollapsableListFrameConstraint"



local NexusPluginFramework = require(script.Parent.Parent.Parent.Parent:WaitForChild("NexusPluginFrameworkProject")):GetContext(script)
local NexusContainer = NexusPluginFramework:GetResource("Base.NexusContainer")
local NexusEventCreator = NexusPluginFramework:GetResource("NexusInstance.Event.NexusEventCreator")

local NexusCollapsableListFrameConstraint = NexusContainer:Extend()
NexusCollapsableListFrameConstraint:SetClassName(CLASS_NAME)
NexusPluginFramework:SetContextResource(NexusCollapsableListFrameConstraint)



--[[
Creates a Nexus Collapsable List Frame Constraint object.
--]]
function NexusCollapsableListFrameConstraint:__new()
	self:InitializeSuper()
	self.Name = CLASS_NAME
	self.__ListFrames = {}
	
	--Create the events.
	self.ListFrameAdded = NexusEventCreator:CreateEvent()
	self.ListFrameRemoved = NexusEventCreator:CreateEvent()
	self.ListFramesUpdated = NexusEventCreator:CreateEvent()
end

--[[
Returns if the constraint contains the list frame.
--]]
function NexusCollapsableListFrameConstraint:ContainsListFrame(ListFrame)
	--Return true if the list frame exists.
	for Key,Value in pairs(self.__ListFrames) do
		if Value == ListFrame then
			return true
		end
	end
	
	--Return false (not contained).
	return false
end

--[[
Returns the list frames part of the constraint.
--]]
function NexusCollapsableListFrameConstraint:GetListFrames()
	--Clone the table.
	local ListFrames = {}
	for Key,Value in pairs(self.__ListFrames) do
		ListFrames[Key] = Value
	end
	
	--Return the table.
	return ListFrames
end

--[[
Returns all of the list frames in the constraint.
--]]
function NexusCollapsableListFrameConstraint:GetAllListFrames(OnlyShowVisible)
	local ListFrames = {}
	
	--[[
	Adds a child frame.
	--]]
	local function AddFrame(Frame)
		--Return if it isn't a frame.
		if not Frame:IsA("NexusCollapsableListFrame") then
			return
		end
		
		--Add the frame.
		if Frame.Visible then
			table.insert(ListFrames,Frame)
			
			--Add the children if it is expanded or all are added.
			if OnlyShowVisible ~= true or Frame.Expanded then
				for _,SubFrame in pairs(Frame:GetCollapsableContainer():GetChildren()) do
					AddFrame(SubFrame)
				end
			end
		end
	end
	
	--Add the frames.
	for _,Frame in pairs(self.__ListFrames) do
		AddFrame(Frame)
	end
	
	--Return the table.
	return ListFrames
end

--[[
Sorts the list frames using a given function.
--]]
function NexusCollapsableListFrameConstraint:SortListFrames(SortFunction)
	--Sort the list frames.
	table.sort(self.__ListFrames,SortFunction)
	
	--Fire the updated event.
	self.ListFramesUpdated:Fire()
end
--[[
Adds a list frame to the constraint.
--]]
function NexusCollapsableListFrameConstraint:AddListFrame(ListFrame,Index)
	--Return if the list frame is in the constraint.
	if self:ContainsListFrame(ListFrame) then
		return
	end
	
	--Insert the list frame.
	if Index then
		table.insert(self.__ListFrames,Index,ListFrame)
	else
		table.insert(self.__ListFrames,ListFrame)
	end
	
	--Fire the updated events.
	self.ListFrameAdded:Fire(ListFrame)
	self.ListFramesUpdated:Fire()
end

--[[
Removes a list frame to the constraint.
--]]
function NexusCollapsableListFrameConstraint:RemoveListFrame(ListFrame)
	--Get the index.
	local Index
	for Key,Value in pairs(self.__ListFrames) do
		if Value == ListFrame then
			Index = Key
			break
		end
	end
	
	--Remove the index if it exists and fire the events.
	if Index then
		table.remove(self.__ListFrames,Index)
		self.ListFrameRemoved:Fire(ListFrame)
		self.ListFramesUpdated:Fire()
	end
end

--[[
Removes all of the list frames to the constraint.
--]]
function NexusCollapsableListFrameConstraint:ClearListFrames()
	local ListFrames = self:GetListFrames()
	
	--Clear the list frames.
	self.__ListFrames = {}
	for _,ListFrame in pairs(ListFrames) do
		self.ListFrameRemoved:Fire(ListFrame)
	end
	
	--Fire the updated event.
	self.ListFramesUpdated:Fire()
end



return NexusCollapsableListFrameConstraint