local M=script.Parent.Parent local B=require(script.Parent.Assets)local f=require(M.Creator)local e=require(M.Packages.Flipper)local D=f.New local A=f.AddSignal return function(e)local n={}local H=require(M)local function b(M,B,e,n)local H={Callback=n or function() end}H.Frame=D("\084\101\120\116\066\117\116\116\111\110",{Size=UDim2.new(0,34,1,-8);AnchorPoint=Vector2.new(1,0);BackgroundTransparency=1,Parent=e,Position=B;Text="";ThemeTag={BackgroundColor3="\084\101\120\116"}},{D("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(0,7)});D("\073\109\097\103\101\076\097\098\101\108",{Image=M,Size=UDim2.fromOffset(16,16);Position=UDim2.fromScale(.5,.5);AnchorPoint=Vector2.new(.5,.5);BackgroundTransparency=1;Name="\073\099\111\110";ThemeTag={ImageColor3="\084\101\120\116"}})})local b,d=f.SpringMotor(1,H.Frame,"\066\097\099\107\103\114\111\117\110\100\084\114\097\110\115\112\097\114\101\110\099\121")A(H.Frame.MouseEnter,function()d(.94)end)A(H.Frame.MouseLeave,function()d(1,true)end)A(H.Frame.MouseButton1Down,function()d(.96)end)A(H.Frame.MouseButton1Up,function()d(.94)end)A(H.Frame.MouseButton1Click,H.Callback)H.SetCallback=function(M)H.Callback=M end return H end n.Frame=D("\070\114\097\109\101",{Size=UDim2.new(1,0,0,42);BackgroundTransparency=1;Parent=e.Parent},{D("\070\114\097\109\101",{Size=UDim2.new(1,-16,1,0),Position=UDim2.new(0,16,0,0);BackgroundTransparency=1},{D("\085\073\076\105\115\116\076\097\121\111\117\116",{Padding=UDim.new(0,5),FillDirection=Enum.FillDirection.Horizontal;SortOrder=Enum.SortOrder.LayoutOrder}),D("\084\101\120\116\076\097\098\101\108",{RichText=true,Text=e.Title;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.fromScale(0,1),AutomaticSize=Enum.AutomaticSize.X,BackgroundTransparency=1;ThemeTag={TextColor3="\084\101\120\116"}}),D("\084\101\120\116\076\097\098\101\108",{RichText=true;Text=e.SubTitle,TextTransparency=.4;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.fromScale(0,1);AutomaticSize=Enum.AutomaticSize.X,BackgroundTransparency=1;ThemeTag={TextColor3="\084\101\120\116"}})});D("\070\114\097\109\101",{BackgroundTransparency=.5;Size=UDim2.new(1,0,0,1);Position=UDim2.new(0,0,1,0);ThemeTag={BackgroundColor3="\084\105\116\108\101\066\097\114\076\105\110\101"}})})n.CloseButton=b(B.Close,UDim2.new(1,-4,0,4),n.Frame,function()H.Window:Dialog({Title="\067\108\111\115\101",Content="\065\114\101 \121\111\117 \115\117\114\101 \121\111\117 \119\097\110\116 \116\111 \117\110\108\111\097\100 \116\104\101 \105\110\116\101\114\102\097\099\101\063";Buttons={{Title="\089\101\115",Callback=function()H:Destroy()end},{Title="\078\111"}}})end)n.MaxButton=b(B.Max,UDim2.new(1,-40,0,4),n.Frame,function()e.Window.Maximize(not e.Window.Maximized)end)n.MinButton=b(B.Min,UDim2.new(1,-80,0,4),n.Frame,function()H.Window:Minimize()end)return n end
local Root = script.Parent.Parent
local Assets = require(script.Parent.Assets)
local Creator = require(Root.Creator)
local Flipper = require(Root.Packages.Flipper)

local New = Creator.New
local AddSignal = Creator.AddSignal

return function(Config)
	local TitleBar = {}

	local Library = require(Root)

	local function BarButton(Icon, Pos, Parent, Callback)
		local Button = {
			Callback = Callback or function() end,
		}

		Button.Frame = New("TextButton", {
			Size = UDim2.new(0, 34, 1, -8),
			AnchorPoint = Vector2.new(1, 0),
			BackgroundTransparency = 1,
			Parent = Parent,
			Position = Pos,
			Text = "",
			ThemeTag = {
				BackgroundColor3 = "Text",
			},
		}, {
			New("UICorner", {
				CornerRadius = UDim.new(0, 7),
			}),
			New("ImageLabel", {
				Image = Icon,
				Size = UDim2.fromOffset(16, 16),
				Position = UDim2.fromScale(0.5, 0.5),
				AnchorPoint = Vector2.new(0.5, 0.5),
				BackgroundTransparency = 1,
				Name = "Icon",
				ThemeTag = {
					ImageColor3 = "Text",
				},
			}),
		})

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

		AddSignal(Button.Frame.MouseEnter, function()
			SetTransparency(0.94)
		end)
		AddSignal(Button.Frame.MouseLeave, function()
			SetTransparency(1, true)
		end)
		AddSignal(Button.Frame.MouseButton1Down, function()
			SetTransparency(0.96)
		end)
		AddSignal(Button.Frame.MouseButton1Up, function()
			SetTransparency(0.94)
		end)
		AddSignal(Button.Frame.MouseButton1Click, Button.Callback)

		Button.SetCallback = function(Func)
			Button.Callback = Func
		end

		return Button
	end

	TitleBar.Frame = New("Frame", {
		Size = UDim2.new(1, 0, 0, 42),
		BackgroundTransparency = 1,
		Parent = Config.Parent,
	}, {
		New("Frame", {
			Size = UDim2.new(1, -16, 1, 0),
			Position = UDim2.new(0, 16, 0, 0),
			BackgroundTransparency = 1,
		}, {
			New("UIListLayout", {
				Padding = UDim.new(0, 5),
				FillDirection = Enum.FillDirection.Horizontal,
				SortOrder = Enum.SortOrder.LayoutOrder,
			}),
			New("TextLabel", {
				RichText = true,
				Text = Config.Title,
				FontFace = Font.new(
					"rbxasset://fonts/families/GothamSSm.json",
					Enum.FontWeight.Regular,
					Enum.FontStyle.Normal
				),
				TextSize = 12,
				TextXAlignment = "Left",
				TextYAlignment = "Center",
				Size = UDim2.fromScale(0, 1),
				AutomaticSize = Enum.AutomaticSize.X,
				BackgroundTransparency = 1,
				ThemeTag = {
					TextColor3 = "Text",
				},
			}),
			New("TextLabel", {
				RichText = true,
				Text = Config.SubTitle,
				TextTransparency = 0.4,
				FontFace = Font.new(
					"rbxasset://fonts/families/GothamSSm.json",
					Enum.FontWeight.Regular,
					Enum.FontStyle.Normal
				),
				TextSize = 12,
				TextXAlignment = "Left",
				TextYAlignment = "Center",
				Size = UDim2.fromScale(0, 1),
				AutomaticSize = Enum.AutomaticSize.X,
				BackgroundTransparency = 1,
				ThemeTag = {
					TextColor3 = "Text",
				},
			}),
		}),
		New("Frame", {
			BackgroundTransparency = 0.5,
			Size = UDim2.new(1, 0, 0, 1),
			Position = UDim2.new(0, 0, 1, 0),
			ThemeTag = {
				BackgroundColor3 = "TitleBarLine",
			},
		}),
	})

	TitleBar.CloseButton = BarButton(Assets.Close, UDim2.new(1, -4, 0, 4), TitleBar.Frame, function()
		Library.Window:Dialog({
			Title = "Close",
			Content = "Are you sure you want to unload the interface?",
			Buttons = {
				{
					Title = "Yes",
					Callback = function()
						Library:Destroy()
					end,
				},
				{
					Title = "No",
				},
			},
		})
	end)
	TitleBar.MaxButton = BarButton(Assets.Max, UDim2.new(1, -40, 0, 4), TitleBar.Frame, function()
		Config.Window.Maximize(not Config.Window.Maximized)
	end)
	TitleBar.MinButton = BarButton(Assets.Min, UDim2.new(1, -80, 0, 4), TitleBar.Frame, function()
		Library.Window:Minimize()
	end)

	return TitleBar
end
