local LoadingManager = class("LoadingManager", BaseModule)

function LoadingManager:showLoading(loadingType, loadingCanvas, callback)
	if self.loadingType then
		return
	end
	self.loadingType = loadingType

	if loadingType == UIManager.LOADING_TYPE.CLOUD then
		self:showCloudLoading(loadingCanvas, callback)
	else
		self:showBlackLoading(callback)
	end
end

function LoadingManager:closeLoading(loadingType, callback)
	if self.loadingType == nil then
		return
	end
	self.loadingType = nil
	if loadingType == UIManager.LOADING_TYPE.CLOUD then
		self:hideCloudLoading(callback)
	else
		UIManager:getBlackLoadingImg():setActive(false)
		callback()
	end
end

function LoadingManager:showBlackLoading(callback)
	UIManager:getBlackLoadingImg():setActive(true)
	callback()
end

function LoadingManager:showCloudLoading(loadingCanvas, callback)
	if self.cloudLadingUI == nil then
		self.cloudLadingUI = require("app/ui/loading/loading_cloud_ui"):create()
		self.cloudLadingUI:init(loadingCanvas, callback)
	else
		self.cloudLadingUI:showLoading(callback)
	end
end

function LoadingManager:hideCloudLoading(callback)
	if self.cloudLadingUI then
		self.cloudLadingUI:hideLoading(callback)
	else
		callback()
	end
end

return LoadingManager