local BattleSelectSkillCell = class("BattleSelectSkillCell", BaseCell)

local SELECT_SKILL_CELL = "app/ui/battle/cell/select_skill_cell"

function BattleSelectSkillCell:refresh(skillId, func)
    local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
    if not cfg then
        return
    end

    local value
    local valueStr
    if cfg.type == 5 then
        self.value = math.random(cfg.attr.minnum, cfg.attr.maxnum)
        self.value = self.value // 100 * 100
        valueStr = GFunc.getPerStr(cfg.attr.type, self.value)
        value = ModuleManager.HeroManager:getSkillRogueDesc(skillId, self.value)
    else
        self.value = nil
        if skillId == 24 then -- 特殊处理
            if ModuleManager.BattleManager.battleController then
                value = ModuleManager.BattleManager.battleController.battleData:getSkillCount(skillId)+1
                value = I18N:getText("skill_rogue", skillId, "desc", value)
            end
        else
            value = ModuleManager.HeroManager:getSkillRogueDesc(skillId, self.value)
        end
    end

    local uiMap = self:getUIMap()
    local desc = uiMap["skill_select_cell.desc"]
    desc:setText(value)
    self:getBaseObject():addClickListener(function()
        func(self.value)
    end)
    if not self.selectSkillCell then
        self.selectSkillCell = CellManager:addCellComp(uiMap["skill_select_cell.skill_select_cell"], SELECT_SKILL_CELL)
    end
    self.selectSkillCell:refresh(skillId, nil, valueStr)

    uiMap["skill_select_cell.img"]:setSprite(GConst.ATLAS_PATH.BATTLE, ModuleManager.HeroManager:getSkillRogueBattleBg(skillId))

    local icon = uiMap["skill_select_cell.element_icon"]

    if cfg.skill_position then
        local iconName = uiMap["skill_select_cell.element_icon.name"]
        local atlas, iconSprite = ModuleManager.BattleManager:getElementIcon(cfg.skill_position)
        icon:setVisible(true, 0.4)
        icon:setSprite(atlas, iconSprite)
        iconName:setText(ModuleManager.HeroManager:getMatchTypeName(cfg.skill_position, true))
        desc:setAnchoredPositionY(-15)
    else
        icon:setVisible(false, 0.4)
        desc:setAnchoredPositionY(0)
    end
end

return BattleSelectSkillCell