-- << WARNINGS >>
--CloseX

local function showLoading(warningFrame, status)
	if status then
		warningFrame.LoadingButton.Visible = true
		warningFrame.MainButton.Visible = false
	else
		warningFrame.LoadingButton.Visible = false
		warningFrame.MainButton.Visible = true
	end
end
for _, warningFrame in pairs(main.warnings:GetChildren()) do
	warningFrame.CloseX.MouseButton1Down:Connect(function()
		main.warnings.Visible = false
	end)
	local button = warningFrame:FindFirstChild("MainButton")
	if button then
		local buttonDe = true
		button.MouseButton1Down:Connect(function()
			if buttonDe then
				buttonDe = false
				if warningFrame.Name == "BuyFrame" then
					local productId = button.ProductId.Value
					local productType = button.ProductType.Value
					if productType == "Gamepass" then
						main.marketplaceService:PromptGamePassPurchase(main.player, productId)
					else
						main.marketplaceService:PromptPurchase(main.player, productId)
					end
				elseif warningFrame.Name == "UnBan" then
					showLoading(warningFrame, true)
					main.signals.RequestCommand:InvokeServer(main.pdata.Prefix.."undirectban "..warningFrame.PlrName.Text)
					main:GetModule("PageAdmin"):CreateBanland()
					showLoading(warningFrame, false)
					main.warnings.Visible = false
				elseif warningFrame.Name == "PermRank" then
					showLoading(warningFrame, true)
					local userName = warningFrame.PlrName.Text
					local id = main:GetModule("cf"):GetUserId(userName)
					main.signals.RemovePermRank:InvokeServer{id, userName}
					main:GetModule("PageAdmin"):CreateRanks()
					showLoading(warningFrame, false)
					main.warnings.Visible = false
				elseif warningFrame.Name == "Teleport" then
					showLoading(warningFrame, true)
					local placeId = warningFrame.MainButton.PlaceId.Value
					main.teleportService:Teleport(placeId)
					main.teleportService.TeleportInitFailed:Wait()
					showLoading(warningFrame, false)
				end
				buttonDe = true
			end
		end)
	end
end
main.warnings.Visible = false


