PartyStarter = {}

function PartyStarter:Inform(name)
	ZO_Alert(UI_ALERT_CATEGORY_ALERT, 1, "Attempting to invite ".. name)
end

function PartyStarter:ContextMenu(...)
	-- ok, lets let the menu generate, and add to the end
	self, playerName, rawName = ...
	zo_callLater(function() PartyStarter:AddLines(playerName, rawName) end, 1)
end

function PartyStarter:AddLines(playerName, rawName)
	local localPlayerIsGrouped = IsUnitGrouped("player")
    local localPlayerIsGroupLeader = IsUnitGroupLeader("player")

    -- Our exceptions are guild members, or if you're in a group and not the leader (leaderbug)
	if IsDecoratedDisplayName(playerName) or (localPlayerIsGrouped and not localPlayerIsGroupLeader) then
		AddMenuItem(GetString(SI_CHAT_PLAYER_CONTEXT_ADD_GROUP), function() PartyStarter:Inform(playerName) TryGroupInviteByName(playerName) end)
	end
	ShowMenu(nil, 1)
end

function PartyStarter:Loaded(...)
	local eventCode, addonName = ...
	if addonName ~= "PartyStarter" then return end

	ZO_PreHook(CHAT_SYSTEM, "ShowPlayerContextMenu", function(playerName, rawName) PartyStarter.ContextMenu(CHAT_SYSTEM, playerName, rawName) end)
end



EVENT_MANAGER:RegisterForEvent("PartyStarterLoaded", EVENT_ADD_ON_LOADED, function(...) PartyStarter:Loaded(...) end)