local C=script.Parent.Parent.Parent local U=C.Parent local Z=require(C.Theme)local b=Z.WithTheme local p=require(U.Sift)local w=require(U.t)local m=require(U.Roact)local O=m.createElement local M=require(C.App.Input.Hyperlink.HyperlinkButton)local r=require(C.App.Input.Button.ButtonStack)local W=script.Parent local V=require(W.Window)local X=m.PureComponent:extend(script.Name)X.defaultProps={AutomaticSize=Enum.AutomaticSize.Y;Position=UDim2.fromScale(.5,.5);Size=UDim2.fromOffset(540,0),TitleBarProps={},WindowProps={}}X.validateProps=w.strictInterface({AnchorPoint=w.optional(w.Vector2),AutomaticSize=w.optional(w.EnumItem),Buttons=w.optional(w.table);Position=w.optional(w.UDim2),RichText=w.optional(w.boolean),Size=w.optional(w.UDim2),DetailTitle=w.optional(w.string);DetailBody=w.optional(w.string);DetailContents=w.optional(w.table);BodyText=w.optional(w.string),TitleText=w.optional(w.string),TitleBarProps=w.optional(w.table),WindowProps=w.optional(w.table);[m.Children]=w.optional(w.table);ButtonStackProps=w.optional(w.table);Native=w.optional(w.table)})function X.render(C)local U=C.props local Z=C.state return b(function(C)local b=C["\102\111\110\116\115\047\083\117\098\116\105\116\108\101"]local w=C["\099\111\108\111\114\115\047\070\105\108\108\095\067\111\108\111\114\047\084\101\120\116\047\080\114\105\109\097\114\121"]local m=U.TitleText and O("\084\101\120\116\076\097\098\101\108",{AutomaticSize=Enum.AutomaticSize.Y,BackgroundTransparency=1;FontFace=b.Font;LayoutOrder=1,LineHeight=b.LineHeight;Size=UDim2.fromScale(1,0),Text=U.TitleText;TextSize=b.Size;TextColor3=w.Color;TextTransparency=w.Transparency;TextWrapped=true,TextXAlignment=Enum.TextXAlignment.Left,TextYAlignment=Enum.TextYAlignment.Top})local W=C["\102\111\110\116\115\047\066\111\100\121"]local X=C["\099\111\108\111\114\115\047\070\105\108\108\095\067\111\108\111\114\047\084\101\120\116\047\080\114\105\109\097\114\121"]local i=U.BodyText and O("\084\101\120\116\076\097\098\101\108",{AutomaticSize=Enum.AutomaticSize.Y;BackgroundTransparency=1,FontFace=W.Font;LayoutOrder=2;LineHeight=W.LineHeight;RichText=U.RichText;Size=UDim2.fromScale(1,0),Text=U.BodyText,TextSize=W.Size,TextColor3=X.Color;TextTransparency=X.Transparency;TextWrapped=true;TextXAlignment=Enum.TextXAlignment.Left;TextYAlignment=Enum.TextYAlignment.Top})local l=U.DetailTitle or U.DetailBody or U.DetailContents local n=l and O(M,{AutomaticSize=Enum.AutomaticSize.XY;LayoutOrder=Z.DetailShown and 4 or 3;Size=UDim2.fromScale(0,0);Text=U.DetailButtonText,TextXAlignment=Enum.TextXAlignment.Left})local o=U.Buttons and O(r,p.Dictionary.join({AnchorPoint=Vector2.new(.5,.5),Buttons=U.Buttons;Position=UDim2.fromScale(.5,.5),Size=UDim2.new(1,0,1,0);PaddingLeft=UDim.new(0,C["\115\116\121\108\101\115\047\080\097\100\100\105\110\103\047\068\101\102\097\117\108\116\047\079\117\116\101\114\047\076\101\102\116"]),PaddingRight=UDim.new(0,C["\115\116\121\108\101\115\047\080\097\100\100\105\110\103\047\068\101\102\097\117\108\116\047\079\117\116\101\114\047\082\105\103\104\116"])},U.ButtonStackProps))return O(V,p.Dictionary.join({AnchorPoint=U.AnchorPoint;AutomaticSize=U.AutomaticSize;ContentBackgroundColor="\099\111\108\111\114\115\047\066\097\099\107\103\114\111\117\110\100\047\070\105\108\108\095\067\111\108\111\114\047\076\097\121\101\114\047\065\108\116",Position=U.Position;Size=U.Size,Native=U.Native;FooterHeight=o and 80 or 0,FooterContents=o,TitleBarProps=p.Dictionary.join({BackgroundColor="\099\111\108\111\114\115\047\066\097\099\107\103\114\111\117\110\100\047\070\105\108\108\095\067\111\108\111\114\047\076\097\121\101\114\047\065\108\116"},U.TitleBarProps)},U.WindowProps),{Title=m,Body=i;DetailHyperlink=n,Layout=O("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder;Padding=UDim.new(0,12)});Padding=O("\085\073\080\097\100\100\105\110\103",{PaddingBottom=UDim.new(0,C["\115\116\121\108\101\115\047\080\097\100\100\105\110\103\047\067\111\110\116\101\110\116\047\079\117\116\101\114\047\066\111\116\116\111\109"]);PaddingLeft=UDim.new(0,C["\115\116\121\108\101\115\047\080\097\100\100\105\110\103\047\067\111\110\116\101\110\116\047\079\117\116\101\114\047\076\101\102\116"]);PaddingRight=UDim.new(0,C["\115\116\121\108\101\115\047\080\097\100\100\105\110\103\047\067\111\110\116\101\110\116\047\079\117\116\101\114\047\082\105\103\104\116"]);PaddingTop=UDim.new(0,C["\115\116\121\108\101\115\047\080\097\100\100\105\110\103\047\067\111\110\116\101\110\116\047\079\117\116\101\114\047\084\111\112"])})})end)end return X
-- Window: A component that is the base structure for a UI Window

local Winro = script.Parent.Parent.Parent
local Packages = Winro.Parent

local Theme = require(Winro.Theme)
local WithTheme = Theme.WithTheme

local Sift = require(Packages.Sift)
local t = require(Packages.t)
local Roact = require(Packages.Roact)
local new = Roact.createElement

local HyperlinkButton = require(Winro.App.Input.Hyperlink.HyperlinkButton)
local ButtonStack = require(Winro.App.Input.Button.ButtonStack)

local WindowRoot = script.Parent
local Window = require(WindowRoot.Window)

local Dialog = Roact.PureComponent:extend(script.Name)

Dialog.defaultProps = {
	AutomaticSize = Enum.AutomaticSize.Y, --- @defaultProp
	Position = UDim2.fromScale(0.5, 0.5), --- @defaultProp
	Size = UDim2.fromOffset(540, 0), --- @defaultProp
	TitleBarProps = {}, --- @defaultProp
	WindowProps = {}, --- @defaultProp
}

Dialog.validateProps = t.strictInterface({

	--- @prop @optional AnchorPoint Vector2 The Window's anchor point
	AnchorPoint = t.optional(t.Vector2),

	--- @prop @optional AutomaticSize Enum.AutomaticSize Auto sizing
	AutomaticSize = t.optional(t.EnumItem),

	--- @prop @optional Butttons table The buttons to be displayed
	Buttons = t.optional(t.table),

	--- @prop @optional Position UDim2 The Window's position
	Position = t.optional(t.UDim2),

	--- @prop @optional RichText boolean Body text Rich Text
	RichText = t.optional(t.boolean),

	--- @prop @optional Size UDim2 The Window's size
	Size = t.optional(t.UDim2),

	--- @prop @optional DetailTitle string The detail section's tile text
	DetailTitle = t.optional(t.string),

	--- @prop @optional DetailBody string The detail section's body text
	DetailBody = t.optional(t.string),

	--- @prop @optional DetailContents table The contents to display in the detail section
	DetailContents = t.optional(t.table),

	--- @prop @optional BodyText string Body text
	BodyText = t.optional(t.string),

	--- @prop @optional TitleText string Title text
	TitleText = t.optional(t.string),

	--- @prop @optional TitleBarProps table The props to be provided to the Title Bar
	TitleBarProps = t.optional(t.table),

	--- @prop @optional WindowProps table The props to be provided to the Window
	WindowProps = t.optional(t.table),

	--- @prop @optional [Roact.Children] table The contents to display in the window area
	[Roact.Children] = t.optional(t.table),

	--- @prop @optional ButtonStackProps table ButtonStackProps
	ButtonStackProps = t.optional(t.table),

	--- @prop @optional Native table Native props
	Native = t.optional(t.table),
})

function Dialog:render()
	local props = self.props
	local state = self.state

	return WithTheme(function(Theme)
	
		-- ////////// Title

		local TitleFontStyle = Theme['fonts/Subtitle']
		local TitleTextStyle = Theme['colors/Fill_Color/Text/Primary']

		local Title = props.TitleText and new('TextLabel', {
			AutomaticSize = Enum.AutomaticSize.Y,
			BackgroundTransparency = 1,
			FontFace = TitleFontStyle.Font,
			LayoutOrder = 1,
			LineHeight = TitleFontStyle.LineHeight,
			Size = UDim2.fromScale(1, 0),
			Text = props.TitleText,
			TextSize = TitleFontStyle.Size,
			TextColor3 = TitleTextStyle.Color,
			TextTransparency = TitleTextStyle.Transparency,
			TextWrapped = true,
			TextXAlignment = Enum.TextXAlignment.Left,
			TextYAlignment = Enum.TextYAlignment.Top,
		})

		-- ////////// Body

		local BodyFontStyle = Theme['fonts/Body']
		local BodyTextStyle = Theme['colors/Fill_Color/Text/Primary']

		local Body = props.BodyText and new('TextLabel', {
			AutomaticSize = Enum.AutomaticSize.Y,
			BackgroundTransparency = 1,
			FontFace = BodyFontStyle.Font,
			LayoutOrder = 2,
			LineHeight = BodyFontStyle.LineHeight,
			RichText = props.RichText,
			Size = UDim2.fromScale(1, 0),
			Text = props.BodyText,
			TextSize = BodyFontStyle.Size,
			TextColor3 = BodyTextStyle.Color,
			TextTransparency = BodyTextStyle.Transparency,
			TextWrapped = true,
			TextXAlignment = Enum.TextXAlignment.Left,
			TextYAlignment = Enum.TextYAlignment.Top,
		})

		-- ////////// Detail Hyperlink
		
		-- Check if the detail container should be craeted
		local DetailContainerEnabled = props.DetailTitle or props.DetailBody or props.DetailContents

		local DetailHyperlink = DetailContainerEnabled and new(HyperlinkButton, {
			AutomaticSize = Enum.AutomaticSize.XY,
			LayoutOrder = state.DetailShown and 4 or 3,
			Size = UDim2.fromScale(0, 0),
			Text = props.DetailButtonText,
			TextXAlignment = Enum.TextXAlignment.Left,
		})

		-- ////////// Buttons

		local Buttons = props.Buttons and new(ButtonStack, Sift.Dictionary.join({
			AnchorPoint = Vector2.new(0.5, 0.5),
			Buttons = props.Buttons,
			Position = UDim2.fromScale(0.5, 0.5),
			Size = UDim2.new(1, 0, 1, 0),
			PaddingLeft = UDim.new(0, Theme['styles/Padding/Default/Outer/Left']),
			PaddingRight = UDim.new(0, Theme['styles/Padding/Default/Outer/Right']),
		}, props.ButtonStackProps))

		-- ////////// Dialog
		return new(Window, Sift.Dictionary.join({
			AnchorPoint = props.AnchorPoint,
			AutomaticSize = props.AutomaticSize,
			ContentBackgroundColor = 'colors/Background/Fill_Color/Layer/Alt',
			Position = props.Position,
			Size = props.Size,
			Native = props.Native,

			FooterHeight = Buttons and 80 or 0,
			FooterContents = Buttons,

			TitleBarProps = Sift.Dictionary.join({
				BackgroundColor = 'colors/Background/Fill_Color/Layer/Alt',
			}, props.TitleBarProps),
		}, props.WindowProps), {
			Title = Title,
			Body = Body,
			DetailHyperlink = DetailHyperlink,

			Layout = new('UIListLayout', {
				SortOrder = Enum.SortOrder.LayoutOrder,
				Padding = UDim.new(0, 12),
			}),
			Padding = new('UIPadding', {
				PaddingBottom = UDim.new(0, Theme['styles/Padding/Content/Outer/Bottom']),
				PaddingLeft = UDim.new(0, Theme['styles/Padding/Content/Outer/Left']),
				PaddingRight = UDim.new(0, Theme['styles/Padding/Content/Outer/Right']),
				PaddingTop = UDim.new(0, Theme['styles/Padding/Content/Outer/Top']),
			}),
		})
	end)
end

return Dialog
