local DailyChallengeTaskUI = class("DailyChallengeTaskUI", BaseUI)

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

function DailyChallengeTaskUI:isFullScreen()
    return false
end

function DailyChallengeTaskUI:getPrefabPath()
    return "assets/prefabs/ui/daily_challenge/daily_challenge_task_ui.prefab"
end

---- 构建数据
function DailyChallengeTaskUI:ctor()
    local battleController = ModuleManager.BattleManager.battleController
    if not battleController then
        self.taskCurProgress = {}
        return
    end

    self.taskCurProgress = ModuleManager.DailyChallengeManager:getCurTaskProgress(battleController)
end

function DailyChallengeTaskUI:onLoadRootComplete()
    DataManager.DailyChallengeData:markPopTask()
    self:_display()
    self:_addListeners()
end

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

    local tasks = DataManager.DailyChallengeData:getTasks()
    for i, cell in ipairs(self.taskCells) do
        if tasks[i] then
            cell:refresh(tasks[i], self.taskCurProgress[tasks[i].task_id])
        end
    end

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

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

return DailyChallengeTaskUI