-----------------------------------------------------------------------------------------------------------------------------------------
-- VRP
-----------------------------------------------------------------------------------------------------------------------------------------
local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
vRP = Proxy.getInterface("vRP")
-----------------------------------------------------------------------------------------------------------------------------------------
-- CONNECTION
-----------------------------------------------------------------------------------------------------------------------------------------
vSERVER = Tunnel.getInterface("party")
-----------------------------------------------------------------------------------------------------------------------------------------
-- VARIABLES
-----------------------------------------------------------------------------------------------------------------------------------------
local Open = false
-----------------------------------------------------------------------------------------------------------------------------------------
-- PARTY
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterCommand("Groups", function()
	if not Open then
		Open = true
		SetNuiFocus(true, true)
		SendNUIMessage({ name = "Open", payload = vSERVER.GetRooms() })
	end
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- KEYMAPPING
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterKeyMapping("Groups", "Abrir os grupos", "keyboard", "M")
-----------------------------------------------------------------------------------------------------------------------------------------
-- GETROOMS
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("GetRooms", function(Data, Callback)
	Callback(vSERVER.GetRooms())
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- GETMEMBERS
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("GetMembers", function(Data, Callback)
	Callback(vSERVER.GetMembers(Data["id"]))
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- LEAVEROOM
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("LeaveRoom", function(Data, Callback)
	Callback(vSERVER.LeaveRoom())
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- CREATEROOM
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("CreateRoom", function(Data, Callback)
	Callback(vSERVER.CreateRoom(Data["name"], Data["password"]))
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- KICKROOM
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("KickRoom", function(Data, Callback)
	Callback(vSERVER.KickRoom(Data["room"], Data["id"]))
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- ENTERROOM
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("EnterRoom", function(Data, Callback)
	Callback(vSERVER.EnterRoom(Data["room"], Data["password"]))
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- CLOSE
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("Close", function(Data, Callback)
	SetNuiFocus(false, false)
	Open = false

	Callback("Ok")
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- PARTY:RESETNUI
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNetEvent("party:ResetNui")
AddEventHandler("party:ResetNui", function()
	if Open then
		SendNUIMessage({ name = "Reset" })
	end
end)
