local FourteenDayTaskCell = class("FourteenDayTaskCell", BaseCell)
local TASK_BG = {
    "act_common_bg_2",
    "act_common_bg_3",
}
local TASK_ICON_BG = {
    "act_common_board_3",
    "act_common_board_4",
}

function FourteenDayTaskCell:init()
    local uiMap = self:getUIMap()
    self.imgTaskBg = uiMap["fourteen_day_task_cell.img_task_bg"]
    self.imgTask = uiMap["fourteen_day_task_cell.img_task_bg.img_task"]
    self.txDesc = uiMap["fourteen_day_task_cell.tx_desc"]
    self.imgProg = uiMap["fourteen_day_task_cell.prog.img_prog"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
    self.txProg = uiMap["fourteen_day_task_cell.prog.tx_prog"]
    self.txNum = uiMap["fourteen_day_task_cell.tx_num"]
    self.finish = uiMap["fourteen_day_task_cell.finish"]
    self.txFinish = uiMap["fourteen_day_task_cell.finish.bg.tx_finish"]

    self:addClickListener(function()
        if DataManager.FourteenDayData:canGetTaskReward(self.taskId) then
            ModuleManager.FourteenDayManager:reqTaskReward(self.taskId)
        end
	end)
end

function FourteenDayTaskCell:refresh(id)
    self.taskId = id
    local total = DataManager.FourteenDayData:getTaskTarget(self.taskId)
    local cur = DataManager.FourteenDayData:getTaskProgress(self.taskId)
    if DataManager.FourteenDayData:getTaskType(self.taskId) == GConst.TaskConst.TASK_TYPE.X_ARENA_GRADING then
        local minScore = DataManager.ArenaData:getSeasonGradingMinScore()
        total = total - minScore
        cur = cur - minScore
        if cur < 0 then
            cur = 0
        end
    end
    self.imgTask:setSprite(GConst.ATLAS_PATH.ICON_TASK, tostring(DataManager.FourteenDayData:getTaskIcon(self.taskId)))
    self.txDesc:setText(DataManager.FourteenDayData:getTaskDesc(self.taskId))
    self.imgProg.value = cur / total
    self.txProg:setText(cur .. "/" .. total)
    self.txNum:setText(GFunc.getRewardNum(DataManager.FourteenDayData:getTaskRewards(self.taskId)[1]))
    self.txFinish:setText(I18N:getGlobalText(I18N.GlobalConst.STR_COMPLETED))

    self.finish:setActive(false)
    self.baseObject:removeRedPoint()
    if DataManager.FourteenDayData:canGetTaskReward(self.taskId) then
        -- 可领取
        self.baseObject:setSprite(GConst.ATLAS_PATH.ACT_COMMON, TASK_BG[2])
        self.imgTaskBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, TASK_ICON_BG[2])
        self.baseObject:addRedPoint(260, 70, 0.8)
    else
        -- 未完成 or 已领取
        self.baseObject:setSprite(GConst.ATLAS_PATH.ACT_COMMON, TASK_BG[1])
        self.imgTaskBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, TASK_ICON_BG[1])
        self.finish:setActive(DataManager.FourteenDayData:isReceivedTaskReward(self.taskId))
    end
end

return FourteenDayTaskCell