local TournWaveBountyCell = class("TournWaveBountyCell", BaseCell)

function TournWaveBountyCell:init()
    local uiMap = self:getUIMap()
    self.txLevel = uiMap["tourn_wave_bounty_cell.level.tx_level"]
    self.rewardCell1 = uiMap["tourn_wave_bounty_cell.reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
    self.rewardCell2 = uiMap["tourn_wave_bounty_cell.reward_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
    self.rewardCell3 = uiMap["tourn_wave_bounty_cell.reward_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
    self.prog = uiMap["tourn_wave_bounty_cell.progress"]
    self.imgProg = uiMap["tourn_wave_bounty_cell.progress.img_prog"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
end

function TournWaveBountyCell:refresh(level, id)
    self.id = id
    self.txLevel:setText(DataManager.TournWaveData:getLevelTotalScore(level))

    -- 进度条显示
    local helf = self:getBaseObject():getSizeDeltaY() / 2
    if level == 1 then
        self.prog:setAnchoredPositionY(-helf)
        self.prog:setSizeDeltaY(helf)
    elseif level == DataManager.TournWaveData:getBountyMaxLevel() then
        self.prog:setAnchoredPositionY(0)
        self.prog:setSizeDeltaY(helf)
    else
        self.prog:setAnchoredPositionY(0)
        self.prog:setSizeDeltaY(self:getBaseObject():getSizeDeltaY())
    end
    self.imgProg.value = DataManager.TournWaveData:getBountyProgress(level)

    local isGet

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

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

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

-- 领取奖励
function TournWaveBountyCell:onClickReward(grade)
    ModuleManager.TournWaveManager:reqBountyReward(self.id, grade)
end

return TournWaveBountyCell