local e=script.Parent.Parent local F=require(e.Packages.Flipper)local w=require(e.Modules.Creator)local s=w.New local i=F.Spring.new local u=F.Instant.new local S=e.Components local M={Window=nil;Tabs={},Containers={};SelectedTab=0;TabCount=0}function M.Init(F,e)M.Window=e return M end function M.GetCurrentTabPos(e)local F=M.Window.TabHolder.AbsolutePosition.Y local w=M.Tabs[M.SelectedTab].Frame.AbsolutePosition.Y return w-F end function M.New(K,F,i,u)local G=require(e)local P=M.Window local y=G.Elements M.TabCount=M.TabCount+1 local R=M.TabCount local J={Selected=false,Name=F;Type="\084\097\098"}i=i:find("\094\114\098\120\097\115\115\101\116\091\058\047\047\124\105\100\058\047\047\093")==nil and G.Utilities:GetIcon(i)or i J.Frame=s("\084\101\120\116\066\117\116\116\111\110",{Size=UDim2.new(1,0,0,34),BackgroundTransparency=1,Parent=u,ThemeTag={BackgroundColor3="\084\097\098"}},{s("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(0,6)});s("\084\101\120\116\076\097\098\101\108",{AnchorPoint=Vector2.new(0,.5),Position=i~=nil and UDim2.new(0,30,.5,0)or UDim2.new(0,12,.5,0);Text=F;RichText=true;TextColor3=Color3.fromRGB(255,255,255),TextTransparency=0,FontFace=Font.new("\114\098\120\097\115\115\101\116\058\047\047\102\111\110\116\115\047\102\097\109\105\108\105\101\115\047\071\111\116\104\097\109\083\083\109\046\106\115\111\110",Enum.FontWeight.Regular,Enum.FontStyle.Normal);TextSize=12;TextXAlignment="\076\101\102\116",TextYAlignment="\067\101\110\116\101\114",Size=UDim2.new(1,-12,1,0);BackgroundTransparency=1,ThemeTag={TextColor3="\084\101\120\116"}});s("\073\109\097\103\101\076\097\098\101\108",{AnchorPoint=Vector2.new(0,.5);Size=UDim2.fromOffset(16,16),Position=UDim2.new(0,8,.5,0),BackgroundTransparency=1,ImageRectOffset=i and i.ImageRectOffset or Vector2.zero,ImageRectSize=i and i.ImageRectSize or Vector2.zero;Image=i and i.Image or nil;ThemeTag={ImageColor3="\084\101\120\116"}})})local t=s("\085\073\076\105\115\116\076\097\121\111\117\116",{Padding=UDim.new(0,5),SortOrder=Enum.SortOrder.LayoutOrder})J.ContainerFrame=s("\083\099\114\111\108\108\105\110\103\070\114\097\109\101",{Size=UDim2.fromScale(1,1);BackgroundTransparency=1;Parent=P.ContainerHolder;Visible=false;BottomImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\054\056\056\057\056\049\050\055\057\049";MidImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\054\056\056\057\056\049\050\055\050\049",TopImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\054\050\055\054\054\052\049\050\050\053";ScrollBarImageColor3=Color3.fromRGB(255,255,255),ScrollBarImageTransparency=.95,ScrollBarThickness=3,BorderSizePixel=0;CanvasSize=UDim2.fromScale(0,0);ScrollingDirection=Enum.ScrollingDirection.Y},{t,s("\085\073\080\097\100\100\105\110\103",{PaddingRight=UDim.new(0,10),PaddingLeft=UDim.new(0,1),PaddingTop=UDim.new(0,1),PaddingBottom=UDim.new(0,1)})})w.AddSignal(t:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\067\111\110\116\101\110\116\083\105\122\101"),function()if J.ContainerFrame.CanvasSize~=UDim2.fromOffset(0,t.AbsoluteContentSize.Y+2)then J.ContainerFrame.CanvasSize=UDim2.fromOffset(0,t.AbsoluteContentSize.Y+2)end end)J.Motor,J.SetTransparency=w.SpringMotor(1,J.Frame,"\066\097\099\107\103\114\111\117\110\100\084\114\097\110\115\112\097\114\101\110\099\121")w.AddSignal(J.Frame.MouseEnter,function()J.SetTransparency(J.Selected and.85 or.89)end)w.AddSignal(J.Frame.MouseLeave,function()J.SetTransparency(J.Selected and.89 or 1)end)w.AddSignal(J.Frame.MouseButton1Down,function()J.SetTransparency(.92)end)w.AddSignal(J.Frame.MouseButton1Up,function()J.SetTransparency(J.Selected and.85 or.89)end)w.AddSignal(J.Frame.MouseButton1Click,function()M:SelectTab(R)end)M.Containers[R]=J.ContainerFrame M.Tabs[R]=J J.Container=J.ContainerFrame J.ScrollFrame=J.Container function J.Section(F,e)local w={Type="\083\101\099\116\105\111\110"}local s=(require(S.Section))(e,J.Container)w.Container=s.Container w.ScrollFrame=J.Container setmetatable(w,y)return w end J.CreateSection=J.Section J.AddSection=J.Section setmetatable(J,y)return J end function M.SelectTab(F,e)local w=M.Window M.SelectedTab=e for e,F in next,M.Tabs do F.SetTransparency(1)F.Selected=false end M.Tabs[e].SetTransparency(.89)M.Tabs[e].Selected=true w.TabDisplay.Text=M.Tabs[e].Name w.SelectorPosMotor:setGoal(i(M:GetCurrentTabPos(),{frequency=6}))task.spawn(function()w.ContainerHolder.Parent=w.ContainerAnim w.ContainerPosMotor:setGoal(i(15,{frequency=10}))w.ContainerBackMotor:setGoal(i(1,{frequency=10}))task.wait(.12)for e,F in next,M.Containers do F.Visible=false end M.Containers[e].Visible=true w.ContainerPosMotor:setGoal(i(0,{frequency=5}))w.ContainerBackMotor:setGoal(i(0,{frequency=8}))task.wait(.12)w.ContainerHolder.Parent=w.ContainerCanvas end)end return M
local Root = script.Parent.Parent
local Flipper = require(Root.Packages.Flipper)
local Creator = require(Root.Modules.Creator)

local New = Creator.New
local Spring = Flipper.Spring.new
local Instant = Flipper.Instant.new
local Components = Root.Components

local TabModule = {
	Window = nil,
	Tabs = {},
	Containers = {},
	SelectedTab = 0,
	TabCount = 0,
}

function TabModule:Init(Window)
	TabModule.Window = Window
	return TabModule
end

function TabModule:GetCurrentTabPos()
	local TabHolderPos = TabModule.Window.TabHolder.AbsolutePosition.Y
	local TabPos = TabModule.Tabs[TabModule.SelectedTab].Frame.AbsolutePosition.Y

	return TabPos - TabHolderPos
end

function TabModule:New(Title, Icon, Parent)
	local Library = require(Root)
	local Window = TabModule.Window
	local Elements = Library.Elements

	TabModule.TabCount = TabModule.TabCount + 1
	local TabIndex = TabModule.TabCount

	local Tab = {
		Selected = false,
		Name = Title,
		Type = "Tab",
	}

	Icon = Icon:find("^rbxasset[://|id://]") == nil and Library.Utilities:GetIcon(Icon) or Icon

	Tab.Frame = New("TextButton", {
		Size = UDim2.new(1, 0, 0, 34),
		BackgroundTransparency = 1,
		Parent = Parent,
		ThemeTag = {
			BackgroundColor3 = "Tab",
		},
	}, {
		New("UICorner", {
			CornerRadius = UDim.new(0, 6),
		}),
		New("TextLabel", {
			AnchorPoint = Vector2.new(0, 0.5),
			Position = Icon ~= nil and UDim2.new(0, 30, 0.5, 0) or UDim2.new(0, 12, 0.5, 0),
			Text = Title,
			RichText = true,
			TextColor3 = Color3.fromRGB(255, 255, 255),
			TextTransparency = 0,
			FontFace = Font.new(
				"rbxasset://fonts/families/GothamSSm.json",
				Enum.FontWeight.Regular,
				Enum.FontStyle.Normal
			),
			TextSize = 12,
			TextXAlignment = "Left",
			TextYAlignment = "Center",
			Size = UDim2.new(1, -12, 1, 0),
			BackgroundTransparency = 1,
			ThemeTag = {
				TextColor3 = "Text",
			},
		}),
		New("ImageLabel", {
			AnchorPoint = Vector2.new(0, 0.5),
			Size = UDim2.fromOffset(16, 16),
			Position = UDim2.new(0, 8, 0.5, 0),
			BackgroundTransparency = 1,
			ImageRectOffset = Icon and Icon.ImageRectOffset or Vector2.zero,
			ImageRectSize = Icon and Icon.ImageRectSize or Vector2.zero,
			Image = Icon and Icon.Image or nil,
			ThemeTag = {
				ImageColor3 = "Text",
			},
		}),
	})

	local ContainerLayout = New("UIListLayout", {
		Padding = UDim.new(0, 5),
		SortOrder = Enum.SortOrder.LayoutOrder,
	})

	Tab.ContainerFrame = New("ScrollingFrame", {
		Size = UDim2.fromScale(1, 1),
		BackgroundTransparency = 1,
		Parent = Window.ContainerHolder,
		Visible = false,
		BottomImage = "rbxassetid://6889812791",
		MidImage = "rbxassetid://6889812721",
		TopImage = "rbxassetid://6276641225",
		ScrollBarImageColor3 = Color3.fromRGB(255, 255, 255),
		ScrollBarImageTransparency = 0.95,
		ScrollBarThickness = 3,
		BorderSizePixel = 0,
		CanvasSize = UDim2.fromScale(0, 0),
		ScrollingDirection = Enum.ScrollingDirection.Y,
	}, {
		ContainerLayout,
		New("UIPadding", {
			PaddingRight = UDim.new(0, 10),
			PaddingLeft = UDim.new(0, 1),
			PaddingTop = UDim.new(0, 1),
			PaddingBottom = UDim.new(0, 1),
		}),
	})

	Creator.AddSignal(ContainerLayout:GetPropertyChangedSignal("AbsoluteContentSize"), function()
		if Tab.ContainerFrame.CanvasSize ~= UDim2.fromOffset(0, ContainerLayout.AbsoluteContentSize.Y + 2) then
			Tab.ContainerFrame.CanvasSize = UDim2.fromOffset(0, ContainerLayout.AbsoluteContentSize.Y + 2)
		end
	end)

	Tab.Motor, Tab.SetTransparency = Creator.SpringMotor(1, Tab.Frame, "BackgroundTransparency")

	Creator.AddSignal(Tab.Frame.MouseEnter, function()
		Tab.SetTransparency(Tab.Selected and 0.85 or 0.89)
	end)
	Creator.AddSignal(Tab.Frame.MouseLeave, function()
		Tab.SetTransparency(Tab.Selected and 0.89 or 1)
	end)
	Creator.AddSignal(Tab.Frame.MouseButton1Down, function()
		Tab.SetTransparency(0.92)
	end)
	Creator.AddSignal(Tab.Frame.MouseButton1Up, function()
		Tab.SetTransparency(Tab.Selected and 0.85 or 0.89)
	end)
	Creator.AddSignal(Tab.Frame.MouseButton1Click, function()
		TabModule:SelectTab(TabIndex)
	end)

	TabModule.Containers[TabIndex] = Tab.ContainerFrame
	TabModule.Tabs[TabIndex] = Tab

	Tab.Container = Tab.ContainerFrame
	Tab.ScrollFrame = Tab.Container

	function Tab:Section(SectionTitle)
		local Section = { 
			Type = "Section" 
		}

		local SectionFrame = require(Components.Section)(SectionTitle, Tab.Container)
		Section.Container = SectionFrame.Container
		Section.ScrollFrame = Tab.Container

		setmetatable(Section, Elements)
		return Section
	end

	Tab.CreateSection = Tab.Section
	Tab.AddSection = Tab.Section

	setmetatable(Tab, Elements)
	return Tab
end

function TabModule:SelectTab(Tab)
	local Window = TabModule.Window

	TabModule.SelectedTab = Tab

	for _, TabObject in next, TabModule.Tabs do
		TabObject.SetTransparency(1)
		TabObject.Selected = false
	end

	TabModule.Tabs[Tab].SetTransparency(0.89)
	TabModule.Tabs[Tab].Selected = true

	Window.TabDisplay.Text = TabModule.Tabs[Tab].Name
	Window.SelectorPosMotor:setGoal(Spring(TabModule:GetCurrentTabPos(), { frequency = 6 }))

	task.spawn(function()
		Window.ContainerHolder.Parent = Window.ContainerAnim
		
		Window.ContainerPosMotor:setGoal(Spring(15, { frequency = 10 }))
		Window.ContainerBackMotor:setGoal(Spring(1, { frequency = 10 }))

		task.wait(0.12)

		for _, Container in next, TabModule.Containers do
			Container.Visible = false
		end
	
		TabModule.Containers[Tab].Visible = true
		Window.ContainerPosMotor:setGoal(Spring(0, { frequency = 5 }))
		Window.ContainerBackMotor:setGoal(Spring(0, { frequency = 8 }))

		task.wait(0.12)

		Window.ContainerHolder.Parent = Window.ContainerCanvas
	end)
end

return TabModule
