-- Used to set the Notification Modal's text and behavior when actions are selected

local function getText(
	state: UserActions.State,
	action: UserActions.Action,
	setNotificationText: ((string) -> ())?
): string?
	-- Prevents notifications from being shown for opening submenus
	if action.actions then
		return
	end

	-- Handles selection of default subactions
	if action.isDefault and action.parent then
		for _, activeAction in ipairs(state.activeActions) do
			if activeAction.parent and activeAction.parent.name == action.parent.name then
				if callback then
					callback()
					callback = nil
				end

				return activeAction.name .. ": Off"
			end
		end
		return
	end

	-- Handles when notifications for poses are shown
	if action.parent and action.parent.name == UserActions.actions.pose.name then
		local player = Players.LocalPlayer
		local character = if player then player.Character else nil
		local humanoid = if character then character:FindFirstChildOfClass("Humanoid") else nil

		if humanoid then
			if humanoid.MoveDirection ~= Vector3.zero or isJumping(humanoid) then
				-- Prevents notification from being shown while player is moving
				-- and attempting to select a pose
				return
			else
				if callback then
					callback()
					callback = nil
				end

				callback = Emotes.onNextMove(humanoid, function()
					-- Shows the notification modal when player moves after
					-- selecting a pose
					if setNotificationText then
						setNotificationText(action.name .. ": Off")
					end
				end)
			end
		end
	end

	return action.name .. ": " .. if UserActions.isActionActive(state, action) then "On" else "Off"
end

return getText
