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()
	local chapterId = DataManager.PlayerData:getModuleUnlockChapter()
	if chapterId <= 0 then
		return
	end
	DataManager.PlayerData:markShowModuleUnlock()
	UIManager:showUI("app/ui/main_city/module_unlock_ui", {chapterId = chapterId})
end

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

-- 从登录界面第一次进入主城
function MaincityManager:firstEnterMainCity()
	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

function MaincityManager:changeMainCityLeftSideBarOpenOrClose()
	local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI)
	if not mainUI then
		return nil
	end

	self.isLeftSideBarClose = not self.isLeftSideBarClose
	mainUI:refreshLeftBtns()
end

function MaincityManager:getIsMainCityLeftSideBarClose()
	return self.isLeftSideBarClose
end

function MaincityManager:changeMainCityRightSideBarOpenOrClose()
	local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI)
	if not mainUI then
		return nil
	end

	self.isRightSideBarClose = not self.isRightSideBarClose
	mainUI:refreshRightBtns()
end

function MaincityManager:getIsMainCityRightSideBarClose()
	return self.isRightSideBarClose
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.SEVEN_DAY then
		return mainUI:getSideBarActIconPos(moduleKey)
	end
end

-- 模块在侧边栏，-1：左，0：不在侧边栏，1：右
function MaincityManager:getModuleInSideBarWhere(moduleKey)
	local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI)
	if not mainUI then
		return nil
	end

	if mainUI:isInSideBarLeft(moduleKey) then
		return -1
	elseif mainUI:isInSideBarRight(moduleKey) then
		return 1
	else
		return 0
	end
end

function MaincityManager:isActivSideBarModule(moduleKey)
	local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI)
	if not mainUI then
		return nil
	end

	return mainUI:isActivSideBarModule(moduleKey)
end

--@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

return MaincityManager