local MaincityManager = class("MaincityManager", BaseModule)

function MaincityManager:showMainCityUI(isFirstEnter, targetIndex)
	UIManager:showUI(UIManager.UI_PATH.MAINCITY_UI, {isFirstEnter = isFirstEnter, targetIndex = targetIndex})
end

function MaincityManager:showModuleUnlockUI(params)
	UIManager:showUI("app/ui/main_city/module_unlock_ui", params)
end

function MaincityManager:showChapterBoxUI(chapterId)
    UIManager:showUI("app/ui/main_city/chapter_box_ui", {chapterId = chapterId})
end

-- 从登录界面第一次进入主城
function MaincityManager:firstEnterMainCity()
	ModuleManager.ActivityPopManager:setFirstLogin(true)
	if (EDITOR_MODE or not Platform:getIsPublishChannel()) and LocalData:getTutorialSkip() > 0 then
		-- 如果是新号就直接进入战斗
		self:showMainCityUI(true)
		return
	end
	if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.START_TUTORIAL, true) then
		DataManager.ChapterData:setChapterId(DataManager.ChapterData.MIN_CHAPTER_ID)
		ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
	else
		self:showMainCityUI(true)
	end
	SDKManager:doUncompletePay()
end

--@region 功能开启
function MaincityManager:getFuncOpenShowList()
	if EDITOR_MODE then
		if LocalData:getFuncOpenPopSkip() > 0 then
			return nil
		end
	end

	local showList = {}
	for moduleKey, info in pairs(ConfigManager:getConfig("func_open")) do
		if ModuleManager:showPop(moduleKey) and not LocalData:getFuncOpenShowList()[moduleKey] then
			if ModuleManager:getIsOpen(moduleKey, true) then
				table.insert(showList, moduleKey)
			-- elseif moduleKey == ModuleManager.MODULE_KEY.EQUIP_SKIN and DataManager.WeaponData:isOpen() then
			-- 	table.insert(showList, moduleKey)
			-- elseif moduleKey == ModuleManager.MODULE_KEY.SKIN and DataManager.SkinData:isOpen() then
			-- 	table.insert(showList, moduleKey)
			end
        end
	end

	return showList
end

function MaincityManager:markFuncOpen(key)
	local list = LocalData:getFuncOpenShowList()
	list[key] = true
	LocalData:setFuncOpenShowList(list)
end

-- 获取主界面各个模块的入口坐标
function MaincityManager:getModuleEntrancePos(moduleKey)
	local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI)
	if not mainUI then
		return nil
	end

	if moduleKey == ModuleManager.MODULE_KEY.TASK then
		return mainUI:getTaskIconPos()
	elseif moduleKey == ModuleManager.MODULE_KEY.MALL_DAILY then
		return mainUI:getMallIconPos()
	elseif moduleKey == ModuleManager.MODULE_KEY.DAILY_CHALLENGE then
		return mainUI:getDailyChallengeIconPos()
	elseif moduleKey == ModuleManager.MODULE_KEY.ARENA then
		return mainUI:getArenaIconPos()
	elseif moduleKey == ModuleManager.MODULE_KEY.IDLE_DROP then
		return mainUI:getIdleIconPos()
	elseif moduleKey == ModuleManager.MODULE_KEY.SUMMON_OPEN then
		return mainUI:getSummonIconPos()
	elseif moduleKey == ModuleManager.MODULE_KEY.FUND or
			moduleKey == ModuleManager.MODULE_KEY.ACT_SEVENDAY then
		return mainUI:getSideBarActIconPos(moduleKey)
	end
end
--@endregion

--@region 战斗力
function MaincityManager:checkShowPowerUI()
	local curPower = DataManager.HeroData:getShowPower()
	local lastPower = DataManager.HeroData:getLastPower()
	if curPower ~= lastPower then
		GFunc.hidePowerToast()
		GFunc.showPowerToast(lastPower, curPower)
	end
end
--@endregion

--@region 跨天数据
function MaincityManager:reqPassDay()
	self:sendMessage(ProtoMsgType.FromMsgEnum.PassDayReq, {}, self.rspPassDay)
end
function MaincityManager:rspPassDay(result)
	DataManager:onCrossDay(result)
end
--@endregion

return MaincityManager