local ActTaskCellV1 = class("ActTaskCellV1", BaseCell)
local REWARD_CELL_COUNT = 1

function ActTaskCellV1:refresh(actId, actTaskId)
    local uiMap = self:getUIMap()
    local bg = uiMap["task_cell.bg"]
    local descTx = uiMap["task_cell.bg.desc_tx"]
    if not self.rewardList then
        self.rewardList = {}
        for i = 1, REWARD_CELL_COUNT do
            table.insert(self.rewardList, CellManager:addCellComp(uiMap["task_cell.bg.reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.REWARD_CELL))
        end
    end
    if not self.slider then
        self.slider = uiMap["task_cell.bg.slider_bg.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
    end
    local sliderTx = uiMap["task_cell.bg.slider_bg.tx"]

    local gotFlag = uiMap["task_cell.bg.got_flag"]
    local gotTx = uiMap["task_cell.bg.got_flag.desc_tx"]
    local funcBtn = uiMap["task_cell.bg.func_btn"]
    local funcTx = uiMap["task_cell.bg.func_btn.desc_tx"]

    local num = DataManager.ActTaskData:getTaskProg(actId, actTaskId)
    local taskType = DataManager.ActTaskData:getTaskType(actTaskId)
    local limit = DataManager.ActTaskData:getTaskTarget(actTaskId)
    local rewards = DataManager.ActTaskData:getTaskReward(actTaskId)
    local hasGot = DataManager.ActTaskData:isTaskReceived(actId, actTaskId)
    -- 修订
    if num > limit then
        num = limit
    end

    descTx:setText(GFunc.getTaskDesc(taskType, limit))
    self.slider.value = num / limit
    sliderTx:setText(num .. "/" .. limit)
    for i = 1, REWARD_CELL_COUNT do
        local reward = rewards and rewards[i]
        if reward then
            self.rewardList[i].baseObject:setActive(true)
            self.rewardList[i]:refreshByConfig(reward)
        else
            self.rewardList[i].baseObject:setActive(false)
        end
    end

    if hasGot then
        gotFlag:setVisible(true)
        gotTx:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_GOGOGO_DESC_13))
        funcBtn:setActive(false)
    else
        gotFlag:setVisible(false)
        funcBtn:setActive(true)
        if num >= limit then
            funcBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_yellow_1")
            funcTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM))
        else
            funcBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_blue_1")
            funcTx:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_GOGOGO_DESC_14))
        end
    end
  
    funcBtn:addClickListener(function()
        if not hasGot then
            if num >= limit then
                -- 领取
                ModuleManager.ActSprintManager:reqTask(actId, actTaskId)
            else
                -- 跳转
                ModuleManager.TaskManager:taskGoto(taskType)
            end
        end
    end)
end

return ActTaskCellV1