local CommonFormationUI = class("CommonFormationUI", BaseUI)

function CommonFormationUI:showCommonBG()
	return false
end

function CommonFormationUI:getPrefabPath()
	return "assets/prefabs/ui/common/common_formation_ui.prefab"
end

function CommonFormationUI:getCurrencyParams()
    if self.currencyParams == nil then
        self.currencyParams = {
            itemIds = {
				GConst.ItemConst.ITEM_ID_GEM,
			},
            showType = GConst.CURRENCY_TYPE.HORIZONTAL
        }
    end

 	return self.currencyParams
end

function CommonFormationUI:ctor(params)
    self.formationType = params.formationType
end

function CommonFormationUI:onLoadRootComplete()
	local uiMap = self.root:genAllChildren()

    uiMap["common_formation_ui.banner.btn_ok.tx_ok"]:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_24))
    uiMap["common_formation_ui.banner.btn_ok"]:addClickListener(function()
        local formation = DataManager.FormationData:getFormation(self.formationType)
        if not formation then
            self:closeUI()
            return
        end
        if self.formationType == GConst.BattleConst.FORMATION_TYPE.DUNGEON_WEAPON then -- 武器副本
            ModuleManager.DungeonWeaponManager:reqFormation(formation)
        elseif self.formationType == GConst.BattleConst.FORMATION_TYPE.DUNGEON_ARMOR then
            ModuleManager.DungeonArmorManager:reqFormation(formation)
        elseif self.formationType == GConst.BattleConst.FORMATION_TYPE.BOSS_RUSH then
            ModuleManager.ActBossRushManager:reqFormation(formation)
        elseif self.formationType == GConst.BattleConst.FORMATION_TYPE.DUNGEON_RUNE then
            ModuleManager.DungeonRuneManager:reqFormation(formation)
        else
            self:closeUI()
        end
	end)

    local heroUI = uiMap["common_formation_ui.hero_ui"]
    heroUI:initPrefabHelper()
    heroUI:genAllChildren()
    self.heroComp = heroUI:addLuaComponent("app/ui/hero/hero_comp")

    self:bind(DataManager.HeroData, "isDirty", function()
        self:onRefresh()
    end)
    self:bind(DataManager.BagData.ItemData, "dirty", function()
        self:onRefresh()
    end)
    self:addEventListener(EventManager.CUSTOM_EVENT.GO_SHOP, function()
        self:closeUI()
    end)

    self:addEventListener(EventManager.CUSTOM_EVENT.FORMATION_CHANGE, function()
        self:closeUI()
    end)
end

function CommonFormationUI:onRefresh()
    self.heroComp:refresh(self.formationType)
end

return CommonFormationUI