local TournWaveRankRewardCell = class("TournWaveRankRewardCell", 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 TournWaveRankRewardCell:init()
    local uiMap = self:getUIMap()

    self.txRank = uiMap["tourn_wave_rank_reward_cell.tx_rank"]
    self.imgRank = uiMap["tourn_wave_rank_reward_cell.img_rank"]
    self.rewards = uiMap["tourn_wave_rank_reward_cell.rewards"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT)
    self.rewardCells = {}
    for i = 1, 3 do
        table.insert(self.rewardCells, uiMap["tourn_wave_rank_reward_cell.rewards.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL))
    end
end

function TournWaveRankRewardCell:refresh(index)
    local info = DataManager.TournWaveData:getRankCfgByIndex(index)
    local ranking1 = info.ranking[1]
    local ranking2 = info.ranking[2]

    if BG[ranking1] then
        self.baseObject:setSprite(GConst.ATLAS_PATH.COMMON, BG[ranking1])
    else
        self.baseObject:setSprite(GConst.ATLAS_PATH.COMMON, BG[4])
    end

    if RANK_IMG[ranking1] then
        self.imgRank:setActive(true)
        self.imgRank:setSprite(GConst.ATLAS_PATH.ACT_COMMON, RANK_IMG[ranking1])
        self.txRank:setText(GConst.EMPTY_STRING)
    else
        self.imgRank:setActive(false)
        local rankStr = ranking1 .. "-"
        if ranking2 then
            rankStr = rankStr .. ranking2
        else
            rankStr = rankStr .. "-"
        end
        if ranking1 == ranking2 then
            rankStr = ranking1
        end
        if index == #DataManager.TournWaveData:getRankIdList() then
            rankStr = ranking1 .. "+"
        end
        self.txRank:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_BOSS_RUSH_DESC_23, rankStr))
    end

    for index, cell in ipairs(self.rewardCells) do
        if info.reward[index] then
            cell:setVisible(true)
            cell:refreshByConfig(info.reward[index])
        else
            cell:setVisible(false)
        end
    end
    self.rewards:RefreshLayout()
end

return TournWaveRankRewardCell