local r=script.Parent.Parent.components local N=require(r.window.button)local j=require(r.window.divider)local E=require(r.window.section)local L=require(r.window.viewport)local q=require(r.window.window)local v=script.Parent.Parent.packages local J=require(v.fusion)local V=false function convertDaysToRelative(r)local N=math.floor(r/365)local j=math.floor((r%365)/30)local E=r%30 local L=""if N>0 then L=N..(" "..(N==1 and"\121\101\097\114"or"\121\101\097\114\115"))elseif j>0 then L=j..(" "..(j==1 and"\109\111\110\116\104"or"\109\111\110\116\104\115"))else L=E..(" "..(E==1 and"\100\097\121"or"\100\097\121\115"))end return L.." \097\103\111"end local y=game:GetService("\080\108\097\121\101\114\115")local k=J.Value(y:GetPlayers())local function T()k:set(y:GetPlayers())end y.PlayerAdded:Connect(T)y.PlayerRemoving:Connect(T)return{name="\112\108\097\121\101\114\115",description="\086\105\101\119 \097\108\108 \116\104\101 \112\108\097\121\101\114\115 \105\110 \116\104\101 \103\097\109\101",arguments={},callback=function(r,v,y)q({title="\080\108\097\121\101\114\115",size=UDim2.fromOffset(320,394)},{J.ForPairs(k,function(r,q)return r,E({text=q.DisplayName..(" \040"..(q.Name.."\041")),subtext=q.UserId,newPage={j({text="\086\105\101\119\112\111\114\116"}),L({object=workspace:FindFirstChild(q.Name),spinning=true,zoom=8,clone=true});j({text="\073\110\102\111"});N({text="\067\114\101\097\116\105\111\110 \068\097\116\101";subtext=convertDaysToRelative(q.AccountAge)..(" \040"..(q.AccountAge.." \100\097\121\115\041")),clickable=false}),N({text="\086\101\114\105\102\105\101\100";subtext=tostring(q.HasVerifiedBadge),clickable=false}),j({text="\065\099\116\105\111\110\115"}),N({text="\084\101\108\101\112\111\114\116";subtext="\084\101\108\101\112\111\114\116\115 \121\111\117\114 \099\104\097\114\097\099\116\101\114 \116\111 \116\104\101 \116\097\114\103\101\116\046",callback=function()local r=v.player.getByName(q.Name)if r then v.player.setPosition(r.Character:GetPivot())return end end});N({text="\083\112\101\099\116\097\116\101",subtext="\083\112\101\099\116\097\116\101\115 \116\104\101 \116\097\114\103\101\116\046 \084\104\101\121 \099\097\110\110\111\116 \115\101\101 \116\104\097\116 \121\111\117\'\114\101 \115\112\101\099\116\097\116\105\110\103\046",callback=function()local r=v.player.getByName(q.Name)V=not V if r then if V then workspace.CurrentCamera.CameraSubject=r.Character return else workspace.CurrentCamera.CameraSubject=v.player.getCharacter()end end end})},callback=function()print("\099\108\105\099\107\101\100")end})end,J.cleanup)})end}
-- < Components >
local Components = script.Parent.Parent.components
local Button = require(Components.window.button)
local Divider = require(Components.window.divider)
local Section = require(Components.window.section)
local Viewport = require(Components.window.viewport)
local Window = require(Components.window.window)

-- < Packages >
local Packages = script.Parent.Parent.packages
local Fusion = require(Packages.fusion)

local spectating = false

-- < Functions >
function convertDaysToRelative(days)
	local years = math.floor(days / 365)
	local months = math.floor((days % 365) / 30)
	local remaining_days = days % 30

	local relative_time = ""

	if years > 0 then
		relative_time = years .. " " .. (years == 1 and "year" or "years")
	elseif months > 0 then
		relative_time = months .. " " .. (months == 1 and "month" or "months")
	else
		relative_time = remaining_days .. " " .. (remaining_days == 1 and "day" or "days")
	end

	return relative_time .. " ago"
end

-- < Player updating >
local Players = game:GetService("Players")
local PlayerList = Fusion.Value(Players:GetPlayers())

local function updatePlayers()
	PlayerList:set(Players:GetPlayers())
end

Players.PlayerAdded:Connect(updatePlayers)
Players.PlayerRemoving:Connect(updatePlayers)

-- < Module >
return {
	name = "players",
	description = "View all the players in the game",
	arguments = {},

	callback = function(_, utils, _)
		Window({
			title = "Players",
			size = UDim2.fromOffset(320, 394),
		}, {
			Fusion.ForPairs(PlayerList, function(index, value)
				return index,
					Section({
						text = value.DisplayName .. " (" .. value.Name .. ")",
						subtext = value.UserId,
						newPage = {
							-- Viewport
							Divider({
								text = "Viewport",
							}),
							Viewport({
								object = workspace:FindFirstChild(value.Name),
								spinning = true,
								zoom = 8,
								clone = true,
							}),

							-- Info
							Divider({
								text = "Info",
							}),
							Button({
								text = "Creation Date",
								subtext = convertDaysToRelative(value.AccountAge)
									.. " ("
									.. value.AccountAge
									.. " days)",
								clickable = false,
							}),
							Button({
								text = "Verified",
								subtext = tostring(value.HasVerifiedBadge),
								clickable = false,
							}),

							-- Actions
							Divider({
								text = "Actions",
							}),
							Button({
								text = "Teleport",
								subtext = "Teleports your character to the target.",
								callback = function()
									local target = utils.player.getByName(value.Name)

									if target then
										utils.player.setPosition(target.Character:GetPivot())

										return
									end
								end,
							}),

							Button({
								text = "Spectate",
								subtext = "Spectates the target. They cannot see that you're spectating.",
								callback = function()
									local target = utils.player.getByName(value.Name)

									spectating = not spectating

									if target then
										if spectating then
											workspace.CurrentCamera.CameraSubject = target.Character

											return
										else
											workspace.CurrentCamera.CameraSubject = utils.player.getCharacter()
										end
									end
								end,
							}),
						},
						callback = function()
							print("clicked")
						end,
					})
			end, Fusion.cleanup),
		})
	end,
}
