local D=script.Parent.Parent.Parent.Parent local E=D.Parent local s=require(D.Theme)local d=s.WithTheme local V=s.RegisterStateAction local B=D.Validators local v=require(B.StyleValidator)local w=require(E.t)local I=require(E.Roact)local A=I.createElement local R=require(D.App.Surface.RoundedSurface)local p="\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 o="\099\111\108\111\114\115\047\083\104\101\108\108\047\070\105\108\108\095\067\111\108\111\114\047\067\097\112\116\105\111\110\095\067\108\111\115\101\095\084\101\120\116\047\080\114\105\109\097\114\121"local q="\099\111\108\111\114\115\047\083\104\101\108\108\047\070\105\108\108\095\067\111\108\111\114\047\067\097\112\116\105\111\110\095\067\108\111\115\101\095\084\101\120\116\047\083\101\099\111\110\100\097\114\121"local e="\099\111\108\111\114\115\047\070\105\108\108\095\067\111\108\111\114\047\083\117\098\116\108\101\047\084\114\097\110\115\112\097\114\101\110\116"local S="\099\111\108\111\114\115\047\083\104\101\108\108\047\070\105\108\108\095\067\111\108\111\114\047\067\097\112\116\105\111\110\095\067\111\110\116\114\111\108\095\067\108\111\115\101\095\070\105\108\108\047\080\114\105\109\097\114\121"local k="\099\111\108\111\114\115\047\083\104\101\108\108\047\070\105\108\108\095\067\111\108\111\114\047\067\097\112\116\105\111\110\095\067\111\110\116\114\111\108\095\067\108\111\115\101\095\070\105\108\108\047\083\101\099\111\110\100\097\114\121"local K="\105\109\097\103\101\115\047\114\111\098\108\111\120\047\105\099\111\110\115\047\110\097\118\105\103\097\116\105\111\110\047\099\108\111\115\101\047\049\120"local N=I.PureComponent:extend(script.Name)N.defaultProps={Width=48}N.validateProps=w.strictInterface({TextColor=w.optional(v),AlwaysShow=w.optional(w.boolean),Width=w.optional(w.numberPositive),[I.Event.Activated]=w.optional(w.callback),[I.Event.MouseButton1Down]=w.optional(w.callback);[I.Event.MouseButton1Up]=w.optional(w.callback),[I.Event.MouseEnter]=w.optional(w.callback),[I.Event.MouseLeave]=w.optional(w.callback)})function N.init(D)V(D,I.Event.Activated,nil)V(D,I.Event.MouseButton1Down,"\080\114\101\115\115\101\100")V(D,I.Event.MouseButton1Up,"\072\111\118\101\114")V(D,I.Event.MouseEnter,"\072\111\118\101\114")V(D,I.Event.MouseLeave,"\082\101\115\116")D:setState({State="\082\101\115\116"})end function N.render(D)local E=D.props local s=D.state return d(function(d)local V=nil local B=nil if s.State=="\082\101\115\116"then if E.AlwaysShow then B=d[o]V=d[S]else B=d[E.TextColor or p]V=d[e]end elseif s.State=="\072\111\118\101\114"then B=d[o]V=d[S]else B=d[q]V=d[k]end return A(R,{AnchorPoint=Vector2.new(1,0),BackgroundColor=V;CornerRadius=UDim.new(0,d["\115\116\121\108\101\115\047\067\111\114\110\101\114\082\097\100\105\117\115\047\068\101\102\097\117\108\116\047\079\117\116\101\114"]);Position=UDim2.fromScale(1,0);Size=UDim2.new(0,E.Width,1,0),ShowTopRightCorner=true},{Button=A("\073\109\097\103\101\066\117\116\116\111\110",{BackgroundTransparency=1,Size=UDim2.fromScale(1,1),[I.Event.Activated]=D[I.Event.Activated];[I.Event.MouseButton1Down]=D[I.Event.MouseButton1Down],[I.Event.MouseButton1Up]=D[I.Event.MouseButton1Up],[I.Event.MouseEnter]=D[I.Event.MouseEnter],[I.Event.MouseLeave]=D[I.Event.MouseLeave]}),Icon=A("\073\109\097\103\101\076\097\098\101\108",{AnchorPoint=Vector2.new(.5,.5);BackgroundTransparency=1;Position=UDim2.fromScale(.5,.5);Size=UDim2.fromOffset(18,18);ImageColor3=B.Color;ImageTransparency=B.Transparency;Image=d[K].Image,ImageRectSize=d[K].ImageRectSize,ImageRectOffset=d[K].ImageRectOffset;ScaleType=Enum.ScaleType.Fit})})end)end return N
-- CaptionClose: The TitleBar close button

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

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

local Validators = Winro.Validators
local StyleValidator = require(Validators.StyleValidator)

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

local RoundedSurface = require(Winro.App.Surface.RoundedSurface)

local CAPTIONCLOSE_TEXT_REST = 'colors/Fill_Color/Text/Primary'
local CAPTIONCLOSE_TEXT_PRIMARY = 'colors/Shell/Fill_Color/Caption_Close_Text/Primary'
local CAPTIONCLOSE_TEXT_SECONDARY = 'colors/Shell/Fill_Color/Caption_Close_Text/Secondary'
local CAPTIONCLOSE_FILL_REST = 'colors/Fill_Color/Subtle/Transparent'
local CAPTIONCLOSE_FILL_PRIMARY = 'colors/Shell/Fill_Color/Caption_Control_Close_Fill/Primary'
local CAPTIONCLOSE_FILL_SECONDARY = 'colors/Shell/Fill_Color/Caption_Control_Close_Fill/Secondary'
local CAPTIONCLOSE_ICON = 'images/roblox/icons/navigation/close/1x'

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

CaptionClose.defaultProps = {
	Width = 48, --- @defaultProp
}

CaptionClose.validateProps = t.strictInterface({

	--- @prop @optional @style TextColor string|table X icon color
	TextColor = t.optional(StyleValidator),

	--- @prop @optional AlwaysShow boolean Determines if the caption close button is always shown
	AlwaysShow = t.optional(t.boolean),

	--- @prop @optional Width number positive The Button's width in pixels
	Width = t.optional(t.numberPositive),

	--- @prop @optional [Roact.Event.Activated] function Roact.Event.Activated
	[Roact.Event.Activated] = t.optional(t.callback),

	--- @prop @optional [Roact.Event.MouseButton1Down] function Roact.Event.MouseButton1Down
	[Roact.Event.MouseButton1Down] = t.optional(t.callback),

	--- @prop @optional [Roact.Event.MouseButton1Up] function Roact.Event.MouseButton1Up
	[Roact.Event.MouseButton1Up] = t.optional(t.callback),

	--- @prop @optional [Roact.Event.MouseEnter] function Roact.Event.MouseEnter
	[Roact.Event.MouseEnter] = t.optional(t.callback),

	--- @prop @optional [Roact.Event.MouseLeave] function Roact.Event.MouseLeave
	[Roact.Event.MouseLeave] = t.optional(t.callback),
})

function CaptionClose:init()
	
	-- Actions
	RegisterStateAction(self, Roact.Event.Activated, nil)
	RegisterStateAction(self, Roact.Event.MouseButton1Down, 'Pressed')
	RegisterStateAction(self, Roact.Event.MouseButton1Up, 'Hover')
	RegisterStateAction(self, Roact.Event.MouseEnter, 'Hover')
	RegisterStateAction(self, Roact.Event.MouseLeave, 'Rest')

	-- Initial state
	self:setState({
		State = 'Rest'
	})
end

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

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

		local FillStyle = nil
		local TextStyle = nil

		if state.State == 'Rest' then
			
			if props.AlwaysShow then
				TextStyle = Theme[CAPTIONCLOSE_TEXT_PRIMARY]
				FillStyle = Theme[CAPTIONCLOSE_FILL_PRIMARY]

			else
				TextStyle = Theme[props.TextColor or CAPTIONCLOSE_TEXT_REST]
				FillStyle = Theme[CAPTIONCLOSE_FILL_REST]
			end

		elseif state.State == 'Hover' then
			TextStyle = Theme[CAPTIONCLOSE_TEXT_PRIMARY]
			FillStyle = Theme[CAPTIONCLOSE_FILL_PRIMARY]

		else
			TextStyle = Theme[CAPTIONCLOSE_TEXT_SECONDARY]
			FillStyle = Theme[CAPTIONCLOSE_FILL_SECONDARY]
		end
		
		return new(RoundedSurface, {
			AnchorPoint = Vector2.new(1, 0),
			BackgroundColor = FillStyle,
			CornerRadius = UDim.new(0, Theme['styles/CornerRadius/Default/Outer']),
			Position = UDim2.fromScale(1, 0),
			Size = UDim2.new(0, props.Width, 1, 0),
			ShowTopRightCorner = true,
		}, {
			Button = new('ImageButton', {
				BackgroundTransparency = 1,
				Size = UDim2.fromScale(1, 1),

				[Roact.Event.Activated] = self[Roact.Event.Activated],
				[Roact.Event.MouseButton1Down] = self[Roact.Event.MouseButton1Down],
				[Roact.Event.MouseButton1Up] = self[Roact.Event.MouseButton1Up],
				[Roact.Event.MouseEnter] = self[Roact.Event.MouseEnter],
				[Roact.Event.MouseLeave] = self[Roact.Event.MouseLeave],
			}),
			Icon = new('ImageLabel', {
				AnchorPoint = Vector2.new(0.5, 0.5),
				BackgroundTransparency = 1,
				Position = UDim2.fromScale(0.5, 0.5),
				Size = UDim2.fromOffset(18, 18),
				ImageColor3 = TextStyle.Color,
				ImageTransparency = TextStyle.Transparency,
				Image = Theme[CAPTIONCLOSE_ICON].Image,
				ImageRectSize = Theme[CAPTIONCLOSE_ICON].ImageRectSize,
				ImageRectOffset = Theme[CAPTIONCLOSE_ICON].ImageRectOffset,
				ScaleType = Enum.ScaleType.Fit,
				--ResampleMode = Enum.ResamplerMode.Pixelated,
			})
		})
	end)
end

return CaptionClose
