local BountyCell = class("BountyCell", BaseCell)

local LEVEL_ICON = {"act_common_bg_14", "act_common_bg_15"}

function BountyCell:init()
    local uiMap = self:getUIMap()
    self.imgLevel = uiMap["fund_cell.level"]
    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 BountyCell:refresh(level)
    self.txLevel:setText(self:getIndex())

    local bountyType = DataManager.ActPvpData.BOUNTY_TYPE
    local isGet
    isGet = DataManager.ActPvpData:getBountyCollected(level, bountyType.NORMAL)
    local reward = DataManager.ActPvpData:getBountyReward(level, bountyType.NORMAL)
    if reward then
        self.rewardCell1:refreshByConfig(reward, isGet, isGet)
    end
    self.rewardCell1:showLock(false)
    if DataManager.ActPvpData:getBountyCanGet(level, bountyType.NORMAL) then
        self.rewardCell1:showFrameAnimation()
        self.rewardCell1.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell1:addClickListener(function()
            self:onClickReward(level, bountyType.NORMAL)
        end)
    else
        self.rewardCell1:hideFrameAnimation()
        self.rewardCell1.baseObject:removeRedPoint()
        self.rewardCell1:addClickListener(nil)
    end

    isGet = DataManager.ActPvpData:getBountyCollected(level, bountyType.SUPERIOR)
    local reward = DataManager.ActPvpData:getBountyReward(level, bountyType.SUPERIOR)
    if reward then
        self.rewardCell2:refreshByConfig(reward, isGet, isGet)
    end
    self.rewardCell2:showLock(not DataManager.ActPvpData:getProBought())
    if DataManager.ActPvpData:getBountyCanGet(level, bountyType.SUPERIOR) then
        self.rewardCell2:showFrameAnimation()
        self.rewardCell2.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell2:addClickListener(function()
            self:onClickReward(level, bountyType.SUPERIOR)
        end)
    else
        self.rewardCell2:hideFrameAnimation()
        self.rewardCell2.baseObject:removeRedPoint()
        self.rewardCell2:addClickListener(nil)
    end

    isGet = DataManager.ActPvpData:getBountyCollected(level, bountyType.SUPERIOR_MAX)
    local reward = DataManager.ActPvpData:getBountyReward(level, bountyType.SUPERIOR_MAX)
    if reward then
        self.rewardCell3:refreshByConfig(reward, isGet, isGet)
    end
    self.rewardCell3:showLock(not DataManager.ActPvpData:getUtralBought())
    if DataManager.ActPvpData:getBountyCanGet(level, bountyType.SUPERIOR_MAX) then
        self.rewardCell3:showFrameAnimation()
        self.rewardCell3.baseObject:addRedPoint(50, 50, 0.6)
        self.rewardCell3:addClickListener(function()
            self:onClickReward(level, bountyType.SUPERIOR_MAX)
        end)
    else
        self.rewardCell3:hideFrameAnimation()
        self.rewardCell3.baseObject:removeRedPoint()
        self.rewardCell3:addClickListener(nil)
    end

    if DataManager.ActPvpData:getBountyLevelEnough(level) then
        self.imgLevel:setSprite(GConst.ATLAS_PATH.ACT_COMMON, LEVEL_ICON[1])
    else
        self.imgLevel:setSprite(GConst.ATLAS_PATH.ACT_COMMON, LEVEL_ICON[2])
    end
end

-- 领取奖励
function BountyCell:onClickReward(level, rewardType)
    ModuleManager.ActPvpManager:reqBountyReward(level, rewardType)
end

return BountyCell