local FundCell = class("FundCell", BaseCell)

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

function FundCell:refresh(level)
    self.txLevel:setText(DataManager.HeroFundData:getLevelWave(level))

    local isGet

    isGet = DataManager.HeroFundData:getFreeGot(level)
    local reward = DataManager.HeroFundData:getReward(level, DataManager.HeroFundData.REWARD_TYPE.FREE)
    if reward then
        self.rewardCell1:refreshByConfig(reward, isGet, isGet)
    end
    self.rewardCell1:showLock(false)
    if DataManager.HeroFundData:getFreeCanGet(level) then
        self.rewardCell1:showFrameAnimation()
        self.rewardCell1.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell1:addClickListener(function()
            self:onClickReward(level, DataManager.HeroFundData.REWARD_TYPE.FREE)
        end)
    else
        self.rewardCell1:hideFrameAnimation()
        self.rewardCell1.baseObject:removeRedPoint()
        self.rewardCell1:addClickListener(nil)
    end

    isGet = DataManager.HeroFundData:getProGot(level)
    local reward = DataManager.HeroFundData:getReward(level, DataManager.HeroFundData.REWARD_TYPE.PRO)
    if reward then
        self.rewardCell2:refreshByConfig(reward, isGet, isGet)
    end
    self.rewardCell2:showLock(not DataManager.HeroFundData:getProBought())
    if DataManager.HeroFundData:getProCanGet(level) then
        self.rewardCell2:showFrameAnimation()
        self.rewardCell2.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell2:addClickListener(function()
            self:onClickReward(level, DataManager.HeroFundData.REWARD_TYPE.PRO)
        end)
    else
        self.rewardCell2:hideFrameAnimation()
        self.rewardCell2.baseObject:removeRedPoint()
        self.rewardCell2:addClickListener(nil)
    end

    isGet = DataManager.HeroFundData:getUtralGot(level)
    local reward = DataManager.HeroFundData:getReward(level, DataManager.HeroFundData.REWARD_TYPE.UTRAL)
    if reward then
        self.rewardCell3:refreshByConfig(reward, isGet, isGet)
    end
    self.rewardCell3:showLock(not DataManager.HeroFundData:getUtralBought())
    if DataManager.HeroFundData:getUtralCanGet(level) then
        self.rewardCell3:showFrameAnimation()
        self.rewardCell3.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell3:addClickListener(function()
            self:onClickReward(level, DataManager.HeroFundData.REWARD_TYPE.UTRAL)
        end)
    else
        self.rewardCell3:hideFrameAnimation()
        self.rewardCell3.baseObject:removeRedPoint()
        self.rewardCell3:addClickListener(nil)
    end
end

-- 领取奖励
function FundCell:onClickReward(level, rewardType)
    ModuleManager.HeroFundManager:reqHeroFundAward(level, rewardType)
end

return FundCell