local RankCell = class("RankCell", BaseCell)

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

local RANK_BG = {"common_bg_8", "common_bg_9", "common_bg_10", "common_bg_11"}

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.COMMON, RANK_BG[index])
    else
        imgBg:setSprite(GConst.ATLAS_PATH.COMMON, RANK_BG[4])
    end

    local txName = uiMap["act_rank_cell.tx_name"]
    local txWin = uiMap["act_rank_cell.tx_win"]
    local txWinDesc = uiMap["act_rank_cell.bg.tx_win_desc"]
    txWinDesc:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_PVP_DESC_17))
    if info then
        txName:setText(info.name)
        txWin:setText(info.total_win)
        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))
        txWin:setText("--")
        self.playerHeadCell:getBaseObject():addClickListener(nil)
        self.playerHeadCell:refresh(3001, 1000, false) -- 默认
    end

end

return RankCell