local ActivityBountyCell = class("ActivityBountyCell", BaseCell)

function ActivityBountyCell:init()
    local uiMap = self:getUIMap()
    self.txLevel = uiMap["activity_bounty_cell.level.tx_level"]
    self.rewardCell1 = uiMap["activity_bounty_cell.reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
    self.rewardCell2 = uiMap["activity_bounty_cell.reward_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
    self.rewardCell3 = uiMap["activity_bounty_cell.reward_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
end

function ActivityBountyCell:refresh(level, data)
    self.gradeData = data
    self.txLevel:setText(level)

    local isGet

    isGet = DataManager.ActivityData:isReceivedBountyReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.FREE)
    self.rewardCell1:refreshByConfig(DataManager.ActivityData:getBountyGradeReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.FREE), isGet, isGet)
    self.rewardCell1:showLock(not DataManager.ActivityData:isBountyGradeUnlock(GConst.ActivityConst.BOUNTY_GRADE_TYPE.FREE))
    if DataManager.ActivityData:canGetBountyReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.FREE) then
        self.rewardCell1.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell1:addClickListener(function()
            self:onClickReward(GConst.ActivityConst.BOUNTY_GRADE_TYPE.FREE)
        end)
    else
        self.rewardCell1.baseObject:removeRedPoint()
        self.rewardCell1:addClickListener(nil)
    end

    isGet = DataManager.ActivityData:isReceivedBountyReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1)
    self.rewardCell2:refreshByConfig(DataManager.ActivityData:getBountyGradeReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1), isGet, isGet)
    self.rewardCell2:showLock(not DataManager.ActivityData:isBountyGradeUnlock(GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1))
    if DataManager.ActivityData:canGetBountyReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1) then
        self.rewardCell2.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell2:addClickListener(function()
            self:onClickReward(GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1)
        end)
    else
        self.rewardCell2.baseObject:removeRedPoint()
        self.rewardCell2:addClickListener(nil)
    end

    isGet = DataManager.ActivityData:isReceivedBountyReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2)
    self.rewardCell3:refreshByConfig(DataManager.ActivityData:getBountyGradeReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2), isGet, isGet)
    self.rewardCell3:showLock(not DataManager.ActivityData:isBountyGradeUnlock(GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2))
    if DataManager.ActivityData:canGetBountyReward(level, GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2) then
        self.rewardCell3.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell3:addClickListener(function()
            self:onClickReward(GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2)
        end)
    else
        self.rewardCell3.baseObject:removeRedPoint()
        self.rewardCell3:addClickListener(nil)
    end
end

-- 领取奖励
function ActivityBountyCell:onClickReward(grade)
    ModuleManager.ActivityManager:reqSummerBountyReward(self.gradeData.id, grade)
end

return ActivityBountyCell