local DungeonArmorTaskUI = class("DungeonArmorTaskUI", BaseUI)

local TASK_CELL = "app/ui/dungeon_armor/cell/task_cell"

function DungeonArmorTaskUI:isFullScreen()
    return false
end

function DungeonArmorTaskUI:getPrefabPath()
    return "assets/prefabs/ui/dungeon_armor/dungeon_armor_task_ui.prefab"
end

---- 构建数据
function DungeonArmorTaskUI:ctor()
    local battleController = ModuleManager.BattleManager.battleController
    if not battleController then
        self.taskCurProgress = {}
        return
    end
    self.armorData = DataManager.DungeonData:getDungeonDataByType(ModuleManager.MODULE_KEY.DUNGEON_ARMOR)
    self.chapterId = battleController.chapterId
    self.taskProgrees = self.armorData:formatTaskByController(battleController, self.chapterId)
end

function DungeonArmorTaskUI:onLoadRootComplete()
    self:_display()
    self:_addListeners()
end

function DungeonArmorTaskUI:_display()
    local uiMap = self.root:genAllChildren()
    if not self.taskCells then
        self.taskCells = {}
        for i = 1, 3 do
            self.taskCells[i] = CellManager:addCellComp(uiMap["dungeon_armor_task_ui.bg.task_cell_" .. i], TASK_CELL)
        end
    end

    for index, cell in ipairs(self.taskCells) do
        local desc, over = self.armorData:getTaskDescByIndex(self.chapterId, index, nil, self.taskProgrees)
        cell:refresh(desc, over)
    end

    uiMap["dungeon_armor_task_ui.bg.title_desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.TASK_NAME))
end

function DungeonArmorTaskUI:_addListeners()
    local uiMap = self.root:genAllChildren()
    uiMap["dungeon_armor_task_ui.bg.close_btn"]:addClickListener(function()
        self:closeUI()
    end)
end

return DungeonArmorTaskUI