local q=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local Q=q:WaitForChild("\077\111\100\117\108\101\115")local R=((game:GetService("\083\116\097\114\116\101\114\080\108\097\121\101\114")):WaitForChild("\083\116\097\114\116\101\114\080\108\097\121\101\114\083\099\114\105\112\116\115")).clientSrc local j=require(R.Components.common.UICorner)local E=require(R.Components.common.Frame)local x=require(Q.Roact)local F=require(Q.RoactRodux)local J=require(R.Components.common.TextLabel)local S=require(R.Components.Timer)local k=x.createElement local i=x.PureComponent:extend("\067\108\111\099\107\083\099\114\101\101\110")local g=game:GetService("\080\108\097\121\101\114\115")local X=g.LocalPlayer function i.render(q)local Q=q.props local R=Q.countDownTextOther local x=Q.countDownText if Q.countDownTime==nil then return nil end local F=tostring(X.UserId)local i=Q.playersWaiting[F]local g=Q.playersPlaying[F]local L=i or g if L==nil then return nil end local h=R and R or x if g then h=x end local v=k(J,{Size=UDim2.new(.4,0,.5,0),TextScaled=true;TextSize=30;AnchorPoint=Vector2.new(.5,0);TextXAlignment=Enum.TextXAlignment.Center,TextYAlignment=Enum.TextYAlignment.Center;Text=h,TextColor3=Q.TextColor3,BackgroundTransparency=Q.BackgroundTransparency or.5,BackgroundColor3=Color3.fromRGB(255,255,255);BorderColor3=Color3.fromRGB(255,255,255)},{UICorner=k(j)})local b=k(S,{key=Q.countDownTime,increment=false;initialTime=Q.countDownTime,TextColor3=Q.TextColor3;Size=UDim2.new(.2,0,.5,0),TextScaled=true;TextSize=30,AnchorPoint=Vector2.new(.5,0);TextXAlignment=Enum.TextXAlignment.Center,TextYAlignment=Enum.TextYAlignment.Center,BackgroundTransparency=Q.BackgroundTransparency or.5,BackgroundColor3=Color3.fromRGB(255,255,255);BorderColor3=Color3.fromRGB(255,255,255)},{UICorner=k(j)})return k(E,{Layout="\076\105\115\116",LayoutDirection="\086\101\114\116\105\099\097\108";HorizontalAlignment="\067\101\110\116\101\114";Padding=UDim.new(0,3);Size=UDim2.new(0,500,0,40);AnchorPoint=Vector2.new(.5,0)},{textEl=v,time=b})end local L=(F.connect(function(q)local Q=q.player.roomId if Q==nil then return{}end local R=q.rooms[Q]return{isFinishScreenOpen=q.player.isFinishScreenOpen;countDownTime=R.countDownTime;countDownText=R.countDownText,countDownTextOther=R.countDownTextOther,playersPlaying=R.playersPlaying,playersWaiting=R.playersWaiting}end))(i)return L
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Modules = ReplicatedStorage:WaitForChild('Modules')
-- local logger = require(Modules.src.utils.Logger)
local clientSrc = game:GetService('StarterPlayer'):WaitForChild('StarterPlayerScripts').clientSrc

local UICorner = require(clientSrc.Components.common.UICorner)
local Frame = require(clientSrc.Components.common.Frame)
local Roact = require(Modules.Roact)
local RoactRodux = require(Modules.RoactRodux)

local TextLabel = require(clientSrc.Components.common.TextLabel)
local Timer = require(clientSrc.Components.Timer)

local createElement = Roact.createElement
local ClockScreen = Roact.PureComponent:extend('ClockScreen')

local Players = game:GetService('Players')
local localPlayer = Players.LocalPlayer

function ClockScreen:render()
	local props = self.props
	local waitingText = props.countDownTextOther
	local playingText = props.countDownText

	if props.countDownTime == nil then
		return nil
	end

	local uid = tostring(localPlayer.UserId)
	local isWaiting = props.playersWaiting[uid]
	local isPlaying = props.playersPlaying[uid]
	local hasPlayer = isWaiting or isPlaying

	if hasPlayer == nil then
		return nil
	end

	local text = waitingText and waitingText or playingText
	if isPlaying then
		text = playingText
	end

	local textEl = createElement(
		TextLabel,
		{
			Size = UDim2.new(0.4, 0, 0.5, 0),
			TextScaled = true,
			TextSize = 30,
			AnchorPoint = Vector2.new(0.5, 0),
			TextXAlignment = Enum.TextXAlignment.Center,
			TextYAlignment = Enum.TextYAlignment.Center,
			Text = text,
			TextColor3 = props.TextColor3,
			BackgroundTransparency = props.BackgroundTransparency or 0.5,
			BackgroundColor3 = Color3.fromRGB(255, 255, 255),
			BorderColor3 = Color3.fromRGB(255, 255, 255),
		},
		{ UICorner = createElement(UICorner) }
	)
	local time = createElement(
		Timer,
		{
			key = props.countDownTime,
			increment = false,
			initialTime = props.countDownTime,
			TextColor3 = props.TextColor3,
			Size = UDim2.new(0.2, 0, 0.5, 0),
			TextScaled = true,
			TextSize = 30,
			AnchorPoint = Vector2.new(0.5, 0),
			TextXAlignment = Enum.TextXAlignment.Center,
			TextYAlignment = Enum.TextYAlignment.Center,
			BackgroundTransparency = props.BackgroundTransparency or 0.5,
			BackgroundColor3 = Color3.fromRGB(255, 255, 255),
			BorderColor3 = Color3.fromRGB(255, 255, 255),
		},
		{ UICorner = createElement(UICorner) }
	)

	return createElement(
		Frame,
		{
			Layout = 'List',
			LayoutDirection = 'Vertical',
			HorizontalAlignment = 'Center',
			Padding = UDim.new(0, 3),
			Size = UDim2.new(0, 500, 0, 40),
			AnchorPoint = Vector2.new(0.5, 0),
		},
		{
			textEl = textEl,
			time = time,
		}
	)
end

local ClockScreenConnected = RoactRodux.connect(function(state)
	local roomId = state.player.roomId
	if roomId == nil then
		return {}
	end

	local room = state.rooms[roomId]

	return {
		isFinishScreenOpen = state.player.isFinishScreenOpen,
		countDownTime = room.countDownTime,
		countDownText = room.countDownText,
		countDownTextOther = room.countDownTextOther,
		playersPlaying = room.playersPlaying,
		playersWaiting = room.playersWaiting,
	}
end)(ClockScreen)

return ClockScreenConnected