local BoxHeroCell = class("BoxHeroCell", BaseCell)

function BoxHeroCell:init()
	local uiMap = self.baseObject:genAllChildren()
    self.heroCell = CellManager:addCellComp(uiMap["cell.hero_cell"], GConst.TYPEOF_LUA_CLASS.HERO_CELL) 
    self.heroNumText = uiMap["cell.num_tx"]
    self.effects = {}
    self.effects[2] = uiMap["cell.effect_node.sfx_ui_zhaohuan_lv_b01"]
    self.effects[3] = uiMap["cell.effect_node.sfx_ui_zhaohuan_lan_b01"]
    self.effects[4] = uiMap["cell.effect_node.sfx_ui_zhaohuan_zi_b01"]
    self:disableAllEffect()
end

function BoxHeroCell:refresh(data)
    self.data = data
    local id = data.id
    local num = data.count
    self.heroCell:setShowRedPoint(false)

    local heroEntity = DataManager.HeroData:getHeroById(id)
    if heroEntity then
        self.heroCell:refresh(heroEntity)
    else
        self.heroCell:refreshWithCfgId(id)
    end
    self.heroNumText:setText("X" .. tostring(num))
end

function BoxHeroCell:playEffect()
    if self.data and self.effects then
        local id = self.data.id
        local heroInfo = ConfigManager:getConfig("hero")[id]
        if heroInfo then
            local qlt = heroInfo.qlt 
            for key, effect in pairs(self.effects) do
                if key == qlt then
                    effect:setActive(true)
                    effect:play()
                else
                    effect:setActive(false)
                end
            end
        end
    end
end

function BoxHeroCell:disableAllEffect()
    if self.effects then
        for key, effect in pairs(self.effects) do
            effect:setActive(false)
        end
    end
end

function BoxHeroCell:setSpineVisible(visible)
    self.heroCell:setSpineVisible(visible)
end

function BoxHeroCell:setVisible(visible)
	self.baseObject:setVisible(visible)
end

return BoxHeroCell