Citizen.CreateThread(function()
	while true do
		Wait(minute * 30)
		TriggerServerEvent("spyoo_inventory:saveMyInventory")
	end
end)

Keys.Register("F1", "F1", "Inventaire", function()
	TriggerServerEvent("spyoo_inventory:openInventory")
end)

RegisterNetEvent("spyoo_inventory:NUIOpenInventory")
AddEventHandler("spyoo_inventory:NUIOpenInventory", function(inventory)
	SetNuiFocus(true, true)
	SendNUIMessage({
		type = 'myInventory',
		inventory = inventory,
		items = Config.Items
	})
end)

RegisterNetEvent("spyoo_inventory:NUIClose")
AddEventHandler("spyoo_inventory:NUIClose", function()
	SetNuiFocus(false, false)
	SendNUIMessage({
		type = 'close'
	})
end)

RegisterNUICallback('NUIClose', function()
	TriggerEvent("spyoo_inventory:NUIClose")
end)

RegisterNUICallback('movedItem', function(data, cb)
	if data.dataNumber then
		data.dataNumber = data.dataNumber + 1
	end
	TriggerServerEvent("spyoo_inventory:movedItem", data.item, data.slot, data.dataNumber)
end)

RegisterNUICallback('useItem', function(data, cb)
	if data.dataNumber then
		data.dataNumber = data.dataNumber + 1
	end
	TriggerServerEvent("spyoo_inventory:useItem", data.item, 1, data.dataNumber)
end)

RegisterNUICallback('renameItem', function(data, cb)
	if data.dataNumber then
		data.dataNumber = data.dataNumber + 1
	end
	TriggerServerEvent("spyoo_inventory:renameItem", data.item, data.dataNumber, data.newLabel)
end)

RegisterNetEvent("spyoo_inventory:refreshInventory")
AddEventHandler("spyoo_inventory:refreshInventory", function(timer)
	if timer then
		Wait(timer)
	end
	TriggerServerEvent("spyoo_inventory:openInventory")
end)

RegisterNUICallback('refreshInventory', function(data, cb)
	TriggerServerEvent("spyoo_inventory:openInventory")
end)

RegisterNetEvent("spyoo_inventory:useItemClient")
AddEventHandler("spyoo_inventory:useItemClient", function(a, b, c)
	TriggerServerEvent("spyoo_inventory:useItem", a, b, c)
end)

for i = 1, 9 do
	Keys.Register(i, i, "Raccourci " .. i, function()
		TriggerServerEvent("spyoo_inventory:useRaccourciItem", i)
	end)
end