local z=script.Parent local y=z.Parent.Packages local C=require(y.Maid)local v=require(y.Flipper)local x=require(y.Roact)local W=x.createElement local c=x.PureComponent:extend(script.Name)function c.init(z)local y=z.props z.Maid=C.new()z.CurrentAnimationState="\082\101\115\116"z.TransparencyMotor=v.SingleMotor.new(1)z.Transparency,z.SetTransparency=x.createBinding(1)z.Maid.TransparencyMotor=function()z.TransparencyMotor:destroy()end z.TransparencyMotor:onStep(function(y)z.SetTransparency(y)end)z.TransparencyMotor:onComplete(function()if z.CurrentAnimationState=="\070\097\100\101\079\117\116"then y.OnFadeOutCompleted()end z.CurrentAnimationState="\082\101\115\116"end)z.Maid.FadeIn=y.FadeInSignal:Connect(function()z.CurrentAnimationState="\070\097\100\101\073\110"z.TransparencyMotor:setGoal(v.Linear.new(0,{velocity=y.FadeInVelocity}))end)z.Maid.FadeOut=y.FadeOutSignal:Connect(function()z.CurrentAnimationState="\070\097\100\101\079\117\116"z.TransparencyMotor:setGoal(v.Linear.new(1,{velocity=y.FadeOutVelocity}))end)end function c.willUnmount(z)z.Maid:Destroy()end function c.render(z)local y=z.props return W("\067\097\110\118\097\115\071\114\111\117\112",{GroupTransparency=z.Transparency;BackgroundTransparency=1;Size=UDim2.fromScale(1,1)},y[x.Children])end return c
local Components = script.Parent
local Packages = Components.Parent.Packages

local Maid = require(Packages.Maid)
local Flipper = require(Packages.Flipper)
local Roact = require(Packages.Roact)
local new = Roact.createElement

-- ////////// AnimationWrapper for Message component

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

function AnimationWrapper:init()
	local props = self.props

	self.Maid = Maid.new()
	self.CurrentAnimationState = 'Rest'

	self.TransparencyMotor = Flipper.SingleMotor.new(1)
	self.Transparency, self.SetTransparency = Roact.createBinding(1)

	self.Maid.TransparencyMotor = function()
		self.TransparencyMotor:destroy()
	end

	-- ////////// Animation

	self.TransparencyMotor:onStep(function(Value)
		self.SetTransparency(Value)
	end)

	self.TransparencyMotor:onComplete(function()
		if self.CurrentAnimationState == 'FadeOut' then
			props.OnFadeOutCompleted()
		end

		self.CurrentAnimationState = 'Rest'
	end)

	self.Maid.FadeIn = props.FadeInSignal:Connect(function()
		self.CurrentAnimationState = 'FadeIn'
		self.TransparencyMotor:setGoal(Flipper.Linear.new(0, {
			velocity = props.FadeInVelocity,
		}))
	end)

	self.Maid.FadeOut = props.FadeOutSignal:Connect(function()
		self.CurrentAnimationState = 'FadeOut'
		self.TransparencyMotor:setGoal(Flipper.Linear.new(1, {
			velocity = props.FadeOutVelocity,
		}))
	end)
end

function AnimationWrapper:willUnmount()
	self.Maid:Destroy()
end

function AnimationWrapper:render()
	local props = self.props

	return new('CanvasGroup', {
		GroupTransparency = self.Transparency,
		BackgroundTransparency = 1,
		Size = UDim2.fromScale(1, 1),
	}, props[Roact.Children])
end

return AnimationWrapper
