local RankRewardcell = class("RankRewardcell", BaseCell)

local RANK_IMG = {"act_ranking_1", "act_ranking_2", "act_ranking_3"}
local BG = {"common_bg_8", "common_bg_9", "common_bg_10", "common_bg_11"}

function RankRewardcell:refresh(ranking1, ranking2, rewards, totalIndex)
    local uiMap = self:getUIMap()

    local rankStr = ranking1 .. "-"
    if ranking2 then
        rankStr = rankStr .. ranking2
    else
        rankStr = rankStr .. "-"
    end
    if ranking1 == ranking2 then
        rankStr = ranking1
    end
    if self:getIndex() == totalIndex then
        rankStr = ranking1 .. "+"
    end
    uiMap["rank_reward_cell.bg.tx_rank"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_BOSS_RUSH_DESC_23, rankStr))
    if not self.rewardCells then
        self.rewardCells = {}
        for i = 1, 2 do
            self.rewardCells[i] = uiMap["rank_reward_cell.bg.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
        end
    end
    for index, cell in ipairs(self.rewardCells) do
        if rewards and rewards[index] then
            cell:refreshByConfig(rewards[index])
            cell:getBaseObject():setActive(true)
        else
            cell:getBaseObject():setActive(false)
        end
    end

    local bg = uiMap["rank_reward_cell.bg"]
    if BG[ranking1] then
        bg:setSprite(GConst.ATLAS_PATH.COMMON, BG[ranking1])
    else
        bg:setSprite(GConst.ATLAS_PATH.COMMON, BG[4])
    end

    local imgRank = uiMap["rank_reward_cell.bg.rank_img"]
    if RANK_IMG[ranking1] then
        imgRank:setSprite(GConst.ATLAS_PATH.ACT_COMMON, RANK_IMG[ranking1])
        imgRank:setVisible(true)
        uiMap["rank_reward_cell.bg.tx_rank"]:setText(GConst.EMPTY_STRING)
    else
        imgRank:setVisible(false)
    end
end

return RankRewardcell