local e=script.Parent.Parent local F=require(e.Modules.Creator)local w=require(e.Components.Button)local s=require(e.Packages.Signal)local i=F.New local u={Window=nil}function u.Init(F,e)u.Window=e return u end function u.Create(S)local M,K={Buttons=0,Closing=s.new();Closed=s.new()},require(e)M.TintFrame=i("\084\101\120\116\066\117\116\116\111\110",{Text="",Size=UDim2.fromScale(1,1),BackgroundColor3=Color3.fromRGB(0,0,0);BackgroundTransparency=1;Parent=u.Window.Root},{i("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(0,8)})})local G,P=F.SpringMotor(1,M.TintFrame,"\066\097\099\107\103\114\111\117\110\100\084\114\097\110\115\112\097\114\101\110\099\121",true)M.ButtonHolder=i("\070\114\097\109\101",{Size=UDim2.new(1,-40,1,-40),AnchorPoint=Vector2.new(.5,.5);Position=UDim2.fromScale(.5,.5);BackgroundTransparency=1},{i("\085\073\076\105\115\116\076\097\121\111\117\116",{Padding=UDim.new(0,10),FillDirection=Enum.FillDirection.Horizontal;HorizontalAlignment=Enum.HorizontalAlignment.Center;SortOrder=Enum.SortOrder.LayoutOrder})})M.ButtonHolderFrame=i("\070\114\097\109\101",{Size=UDim2.new(1,0,0,70),Position=UDim2.new(0,0,1,-70),ThemeTag={BackgroundColor3="\068\105\097\108\111\103\072\111\108\100\101\114"}},{i("\070\114\097\109\101",{Size=UDim2.new(1,0,0,1),ThemeTag={BackgroundColor3="\068\105\097\108\111\103\072\111\108\100\101\114\076\105\110\101"}}),M.ButtonHolder})M.Title=i("\084\101\120\116\076\097\098\101\108",{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.SemiBold,Enum.FontStyle.Normal);Text="\068\105\097\108\111\103",TextColor3=Color3.fromRGB(240,240,240);TextSize=22,TextXAlignment=Enum.TextXAlignment.Left,Size=UDim2.new(1,0,0,22),Position=UDim2.fromOffset(20,25),BackgroundColor3=Color3.fromRGB(255,255,255);BackgroundTransparency=1;ThemeTag={TextColor3="\084\101\120\116"}})M.Scale=i("\085\073\083\099\097\108\101",{Scale=1})local y,R=F.SpringMotor(1.1,M.Scale,"\083\099\097\108\101")M.Root=i("\067\097\110\118\097\115\071\114\111\117\112",{Size=UDim2.fromOffset(300,165),AnchorPoint=Vector2.new(.5,.5);Position=UDim2.fromScale(.5,.5);GroupTransparency=1;Parent=M.TintFrame;ThemeTag={BackgroundColor3="\068\105\097\108\111\103"}},{i("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(0,8)}),i("\085\073\083\116\114\111\107\101",{Transparency=.5,ThemeTag={Color="\068\105\097\108\111\103\066\111\114\100\101\114"}});M.Scale;M.Title,M.ButtonHolderFrame})local J,t=F.SpringMotor(1,M.Root,"\071\114\111\117\112\084\114\097\110\115\112\097\114\101\110\099\121")function M.Open(e)K.DialogOpen=true M.Scale.Scale=1.1 P(.75)t(0)R(1)end function M.Close(e)M.Closing:Fire()K.DialogOpen=false P(1)t(1)R(1.1)M.Root.UIStroke:Destroy()task.wait(.15)M.TintFrame:Destroy()M.Closed:Fire()end function M.Button(i,e,s)M.Buttons=M.Buttons+1 e=e or"\066\117\116\116\111\110"s=s or function() end local u=w("",M.ButtonHolder,true)u.Title.Text=e for e,F in next,M.ButtonHolder:GetChildren()do if F:IsA("\084\101\120\116\066\117\116\116\111\110")then F.Size=UDim2.new(1/M.Buttons,-(((M.Buttons-1)*10)/M.Buttons),0,32)end end F.AddSignal(u.Frame.MouseButton1Click,function()K:SafeCallback(s)pcall(function()M:Close()end)end)return u end return M end return u
local Root = script.Parent.Parent
local Creator = require(Root.Modules.Creator)
local Button_Component = require(Root.Components.Button)
local Signal = require(Root.Packages.Signal)

local New = Creator.New

local Dialog = {
	Window = nil,
}

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

function Dialog:Create()
	local NewDialog, Library = {
		Buttons = 0,
		Closing = Signal.new(),
		Closed = Signal.new()
	}, require(Root)

	NewDialog.TintFrame = New("TextButton", {
		Text = "",
		Size = UDim2.fromScale(1, 1),
		BackgroundColor3 = Color3.fromRGB(0, 0, 0),
		BackgroundTransparency = 1,
		Parent = Dialog.Window.Root,
	}, {
		New("UICorner", {
			CornerRadius = UDim.new(0, 8),
		}),
	})

	local TintMotor, TintTransparency = Creator.SpringMotor(1, NewDialog.TintFrame, "BackgroundTransparency", true)

	NewDialog.ButtonHolder = New("Frame", {
		Size = UDim2.new(1, -40, 1, -40),
		AnchorPoint = Vector2.new(0.5, 0.5),
		Position = UDim2.fromScale(0.5, 0.5),
		BackgroundTransparency = 1,
	}, {
		New("UIListLayout", {
			Padding = UDim.new(0, 10),
			FillDirection = Enum.FillDirection.Horizontal,
			HorizontalAlignment = Enum.HorizontalAlignment.Center,
			SortOrder = Enum.SortOrder.LayoutOrder,
		}),
	})

	NewDialog.ButtonHolderFrame = New("Frame", {
		Size = UDim2.new(1, 0, 0, 70),
		Position = UDim2.new(0, 0, 1, -70),
		ThemeTag = {
			BackgroundColor3 = "DialogHolder",
		},
	}, {
		New("Frame", {
			Size = UDim2.new(1, 0, 0, 1),
			ThemeTag = {
				BackgroundColor3 = "DialogHolderLine",
			},
		}),
		NewDialog.ButtonHolder,
	})

	NewDialog.Title = New("TextLabel", {
		FontFace = Font.new(
			"rbxasset://fonts/families/GothamSSm.json",
			Enum.FontWeight.SemiBold,
			Enum.FontStyle.Normal
		),
		Text = "Dialog",
		TextColor3 = Color3.fromRGB(240, 240, 240),
		TextSize = 22,
		TextXAlignment = Enum.TextXAlignment.Left,
		Size = UDim2.new(1, 0, 0, 22),
		Position = UDim2.fromOffset(20, 25),
		BackgroundColor3 = Color3.fromRGB(255, 255, 255),
		BackgroundTransparency = 1,
		ThemeTag = {
			TextColor3 = "Text",
		},
	})

	NewDialog.Scale = New("UIScale", {
		Scale = 1,
	})

	local ScaleMotor, Scale = Creator.SpringMotor(1.1, NewDialog.Scale, "Scale")

	NewDialog.Root = New("CanvasGroup", {
		Size = UDim2.fromOffset(300, 165),
		AnchorPoint = Vector2.new(0.5, 0.5),
		Position = UDim2.fromScale(0.5, 0.5),
		GroupTransparency = 1,
		Parent = NewDialog.TintFrame,
		ThemeTag = {
			BackgroundColor3 = "Dialog",
		},
	}, {
		New("UICorner", {
			CornerRadius = UDim.new(0, 8),
		}),
		New("UIStroke", {
			Transparency = 0.5,
			ThemeTag = {
				Color = "DialogBorder",
			},
		}),
		NewDialog.Scale,
		NewDialog.Title,
		NewDialog.ButtonHolderFrame,
	})

	local RootMotor, RootTransparency = Creator.SpringMotor(1, NewDialog.Root, "GroupTransparency")

	function NewDialog:Open()
		Library.DialogOpen = true
		NewDialog.Scale.Scale = 1.1
		TintTransparency(0.75)
		RootTransparency(0)
		Scale(1)
	end

	function NewDialog:Close()
		NewDialog.Closing:Fire()
		Library.DialogOpen = false
		TintTransparency(1)
		RootTransparency(1)
		Scale(1.1)
		NewDialog.Root.UIStroke:Destroy()
		task.wait(0.15)
		NewDialog.TintFrame:Destroy()
		NewDialog.Closed:Fire()
	end

	function NewDialog:Button(Title, Callback)
		NewDialog.Buttons = NewDialog.Buttons + 1
		Title = Title or "Button"
		Callback = Callback or function() end

		local Button = Button_Component("", NewDialog.ButtonHolder, true)
		Button.Title.Text = Title

		for _, Btn in next, NewDialog.ButtonHolder:GetChildren() do
			if Btn:IsA("TextButton") then
				Btn.Size = UDim2.new(1 / NewDialog.Buttons, -((NewDialog.Buttons - 1) * 10 / NewDialog.Buttons), 0, 32)
			end
		end

		Creator.AddSignal(Button.Frame.MouseButton1Click, function()
			Library:SafeCallback(Callback)
			pcall(function()
				NewDialog:Close()
			end)
		end)

		return Button
	end

	return NewDialog
end

return Dialog
