--[[
	Sets the current index of the surface art.
]]

modules.setCurrentIndex = function(self)
	return function(index, offset)
		if self.isAnimating then
			return
		end

		-- Can't figure out the right way to do this - we can only calculate how much to move
		-- the frame using the images rendered within this frame, not the entire rendered indexes Frame
		local target = constants.SurfaceArtSelectorItemSize * offset

		self.updateTarget(target)
		self.targetIndex = self.formatTargetIndex(index, offset)

		task.spawn(function()
			self:setState({ offset = math.abs(offset) })
			self.isAnimating = true
			self.motor:setGoal(Otter.spring(target, { frequency = 3 }))
			task.wait(0.5)
			self.isAnimating = false
			self:setState({ selectedIndex = index, offset = 0 })
			self.motor:setGoal(Otter.instant(0))
		end)
	end
end
