local C=script.Parent.Parent.Parent.Parent local U=C.Parent local Z=require(C.Theme)local b=Z.WithTheme local p=Z.RegisterStateAction local w=Z.ApplyDescription local m=require(U.Sift)local O=require(U.t)local M=require(U.Roact)local r=M.createElement local W=script.Parent local V=require(W.Descriptions)local X="\115\116\121\108\101\115\047\065\110\105\109\097\116\105\111\110\083\112\114\105\110\103\080\097\114\097\109\115\047\067\111\110\116\114\111\108\047\073\110\112\117\116\047\066\117\116\116\111\110\047\067\111\108\111\114"local i="\115\116\121\108\101\115\047\065\110\105\109\097\116\105\111\110\083\112\114\105\110\103\080\097\114\097\109\115\047\067\111\110\116\114\111\108\047\073\110\112\117\116\047\066\117\116\116\111\110\047\084\114\097\110\115\112\097\114\101\110\099\121"local l=M.PureComponent:extend(script.Name)l.StyleBindings={"\084\101\120\116"}l.defaultProps={Size=UDim2.fromScale(1,1);Text="\072\121\112\101\114\108\105\110\107"}l.validateProps=O.strictInterface({AutomaticSize=O.optional(O.enum(Enum.AutomaticSize)),Disabled=O.optional(O.boolean);Text=O.optional(O.string),TextXAlignment=O.optional(O.enum(Enum.TextXAlignment)),TextYAlignment=O.optional(O.enum(Enum.TextYAlignment));Size=O.optional(O.UDim2),AnchorPoint=O.optional(O.Vector2),Position=O.optional(O.UDim2),LayoutOrder=O.optional(O.number);Native=O.optional(O.table);[M.Event.Activated]=O.optional(O.callback);[M.Event.MouseButton1Down]=O.optional(O.callback),[M.Event.MouseButton1Up]=O.optional(O.callback),[M.Event.MouseEnter]=O.optional(O.callback),[M.Event.MouseLeave]=O.optional(O.callback)})function l.init(C)for U,Z in pairs(C.StyleBindings)do C[Z],C["\083\101\116"..Z]=M.createBinding({})end p(C,M.Event.Activated,nil)p(C,M.Event.MouseButton1Down,"\080\114\101\115\115\101\100")p(C,M.Event.MouseButton1Up,"\072\111\118\101\114")p(C,M.Event.MouseEnter,"\072\111\118\101\114")p(C,M.Event.MouseLeave,"\082\101\115\116")C:setState({State="\082\101\115\116"})end function l.willUnmount(C)for U,Z in pairs(C.StyleBindings)do local b=C[Z.."\077\111\116\111\114"]if b then pcall(b.destroy,b)C[Z.."\077\111\116\111\114"]=nil end end end function l.ApplyDescription(Z,C,U)w(Z,C,U,U[i],U[X])end function l.render(C)local U=C.props local Z=C.state return b(function(b)if U.Disabled then C:ApplyDescription(V.Disabled,b)elseif Z.State=="\082\101\115\116"then C:ApplyDescription(V.Rest,b)elseif Z.State=="\072\111\118\101\114"then C:ApplyDescription(V.Hover,b)elseif Z.State=="\080\114\101\115\115\101\100"then C:ApplyDescription(V.Pressed,b)end local p=b["\102\111\110\116\115\047\066\111\100\121"]return r("\084\101\120\116\066\117\116\116\111\110",m.Dictionary.join({AutomaticSize=U.AutomaticSize;AnchorPoint=U.AnchorPoint,BackgroundTransparency=1,FontFace=p.Font;LayoutOrder=U.LayoutOrder;LineHeight=p.LineHeight,Position=U.Position;Size=U.Size,Text=U.Text;TextSize=p.Size;TextXAlignment=U.TextXAlignment;TextYalignment=U.TextYAlignment;[M.Event.Activated]=C[M.Event.Activated],[M.Event.MouseButton1Down]=C[M.Event.MouseButton1Down],[M.Event.MouseButton1Up]=C[M.Event.MouseButton1Up];[M.Event.MouseEnter]=C[M.Event.MouseEnter];[M.Event.MouseLeave]=C[M.Event.MouseLeave],TextColor3=C.Text:map(function(C)return C.Color end);TextTransparency=C.Text:map(function(C)return C.Transparency end)},U.Native))end)end return l
-- Hyperlink: Hyperlink Compoent

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 ApplyDescription = Theme.ApplyDescription

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

local HyperlinkRoot = script.Parent
local Descriptions = require(HyperlinkRoot.Descriptions)

local HYPERLINK_TRANSPARENCY_ANIMATION_OPTIONS = 'styles/AnimationSpringParams/Control/Input/Button/Color'
local HYPERLINK_COLOR_ANIMATION_OPTIONS = 'styles/AnimationSpringParams/Control/Input/Button/Transparency'

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

HyperlinkButton.StyleBindings = {
	'Text',
}

HyperlinkButton.defaultProps = {
	Size = UDim2.fromScale(1, 1), --- @defaultProp
	Text = 'Hyperlink', --- @defaultProp
}

HyperlinkButton.validateProps = t.strictInterface({

	--- @prop @optional AutomaticSize Enum.AutmaticSize Autmatic size
	AutomaticSize = t.optional(t.enum(Enum.AutomaticSize)),

	--- @prop @optional Disabled boolean Determines if the HyperlinkButton shows as disabled
	Disabled = t.optional(t.boolean),

	--- @prop @optional Text string The hyperlink's text
	Text = t.optional(t.string),

	--- @prop @optional TextXAlignment Enum.TextXAlignment Horizontal text alignment
	TextXAlignment = t.optional(t.enum(Enum.TextXAlignment)),

	--- @prop @optional TextYAlignment Enum.TextYAlignment Vertical text alignment
	TextYAlignment = t.optional(t.enum(Enum.TextYAlignment)),

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

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

	--- @prop @optional Position UDim2 The Hyperlink's positon
	Position = t.optional(t.UDim2),

	--- @prop @optional LayoutOrder number The Hyperlink's layout order
	LayoutOrder = t.optional(t.number),

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

	--- @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 HyperlinkButton:init()

	-- Create Style Bindings
	for _, StyleBinding in pairs(self.StyleBindings) do
		self[StyleBinding], self['Set' .. StyleBinding] = Roact.createBinding({})
	end

	-- 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 HyperlinkButton:willUnmount()
	
	-- Clear motors for each style binding
	for _, StyleBinding in pairs(self.StyleBindings) do

		-- Look for a motor
		local Motor = self[StyleBinding .. 'Motor']

		-- Remove motor if found
		if Motor then
			pcall(Motor.destroy, Motor)
			self[StyleBinding .. 'Motor'] = nil
		end
	end
end

function HyperlinkButton:ApplyDescription(Description, Theme)
	ApplyDescription(self, Description, Theme, Theme[HYPERLINK_COLOR_ANIMATION_OPTIONS], Theme[HYPERLINK_TRANSPARENCY_ANIMATION_OPTIONS])
end

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

	return WithTheme(function(Theme)
		
		-- Apply Description
		if props.Disabled then
			self:ApplyDescription(Descriptions.Disabled, Theme)
		elseif state.State == 'Rest' then
			self:ApplyDescription(Descriptions.Rest, Theme)
		elseif state.State == 'Hover' then
			self:ApplyDescription(Descriptions.Hover, Theme)
		elseif state.State == 'Pressed' then
			self:ApplyDescription(Descriptions.Pressed, Theme)
		end

		-- ////////// Hyperlink Button

		local HyperlinkButtonFontStyle = Theme['fonts/Body']

		return new('TextButton', Sift.Dictionary.join({
			AutomaticSize = props.AutomaticSize,
			AnchorPoint = props.AnchorPoint,
			BackgroundTransparency = 1,
			FontFace = HyperlinkButtonFontStyle.Font,
			LayoutOrder = props.LayoutOrder,
			LineHeight = HyperlinkButtonFontStyle.LineHeight,
			Position = props.Position,
			Size = props.Size,
			Text = props.Text,
			TextSize = HyperlinkButtonFontStyle.Size,
			TextXAlignment = props.TextXAlignment,
			TextYalignment = props.TextYAlignment,

			[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],

			TextColor3 = self.Text:map(function(Style)
				return Style.Color
			end),
			TextTransparency = self.Text:map(function(Style)
				return Style.Transparency
			end),
		}, props.Native))
	end)
end

return HyperlinkButton
