local RankCell = class("RankCell", BaseCell)

local RANK_ICON = {
    "act_ranking_1",
    "act_ranking_2",
    "act_ranking_3"
}

local RANK_BG = {
    "act_ranking_bg_1",
    "act_ranking_bg_2",
    "act_ranking_bg_3",
    "act_ranking_bg_4"
}

function RankCell:refresh(index, info)
    local uiMap = self:getUIMap()
    if not self.playerHeadCell then
        self.playerHeadCell = CellManager:addCellComp(uiMap["act_rank_cell.player_head_cell"], GConst.TYPEOF_LUA_CLASS.PLAYER_HEAD_CELL)
    end
    uiMap["act_rank_cell.tx_rank"]:setText(index)
    local imgRank = uiMap["act_rank_cell.img_rank"]
    if RANK_ICON[index] then
        imgRank:setVisible(true)
        imgRank:setSprite(GConst.ATLAS_PATH.ACT_COMMON, RANK_ICON[index])
        uiMap["act_rank_cell.tx_rank"]:setText(GConst.EMPTY_STRING)
    else
        imgRank:setVisible(false)
    end

    local imgBg = uiMap["act_rank_cell.bg"]
    if RANK_BG[index] then
        imgBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, RANK_BG[index])
    else
        imgBg:setSprite(GConst.ATLAS_PATH.ACT_COMMON, RANK_BG[4])
    end

    local txName = uiMap["act_rank_cell.tx_name"]
    local txWave = uiMap["act_rank_cell.tx_wave"]
    local txRound = uiMap["act_rank_cell.tx_round"]

    if info then
        txName:setText(info.name)
        txWave:setText(info.wave)
        txRound:setText(info.round)
        self.playerHeadCell:getBaseObject():addClickListener(function()
            ModuleManager.ActBossRushManager:reqOtherPlayerInfo(info.id, function(formation)
                if not self.playerHeadCell or not self.playerHeadCell:getBaseObject() or self.playerHeadCell:getBaseObject():isDestroyed() then
                    return
                end
                ModuleManager.TipsManager:showHeroFormation(self.playerHeadCell:getBaseObject(), formation)
            end)
        end)
        self.playerHeadCell:refresh(info.avatar, info.avatar_frame, false)
    else
        txName:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_BOSS_RUSH_DESC_8))
        txWave:setText("--")
        txRound:setText("--")
        self.playerHeadCell:getBaseObject():addClickListener(nil)
        self.playerHeadCell:refresh(3001, 1000, false) -- 默认
    end

end

return RankCell