local ActivityTaskCell = class("ActivityTaskCell", BaseCell)
local TASK_BG = {
    {GConst.ATLAS_PATH.TASK, "task_bg_2"},
    {GConst.ATLAS_PATH.ACT_SUMMER, "act_summer_bg_2"},
}
local TASK_ICON_BG = {
    {GConst.ATLAS_PATH.TASK, "task_bg_4"},
    {GConst.ATLAS_PATH.ACT_SUMMER, "act_summer_board_1"},
}

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

    self:addClickListener(function()
        if DataManager.ActivityData:canGetTaskReward(self.taskId) and not DataManager.ActivityData:isReceivedTaskReward(self.taskId) then
            ModuleManager.ActivityManager:reqSummerTaskReward(self.taskId)
        end
	end)
end

function ActivityTaskCell:refresh(id)
    self.taskId = id
    local total = DataManager.ActivityData:getTaskTarget(self.taskId)
    local cur = DataManager.ActivityData:getTaskProgress(self.taskId)
    self.imgTask:setSprite(GConst.ATLAS_PATH.ICON_TASK, DataManager.ActivityData:getTaskIcon(self.taskId))
    self.txDesc:setText(DataManager.ActivityData:getTaskDesc(self.taskId))
    self.imgProg.value = cur / total
    self.txProg:setText(cur .. "/" .. total)
    self.txRewardName:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_16))
    self.txNum:setText(DataManager.ActivityData:getTaskRewardNum(self.taskId))
    self.txFinish:setText(I18N:getGlobalText(I18N.GlobalConst.STR_COMPLETED))

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

return ActivityTaskCell