local AttrNodeCell = class("AttrNodeCell", BaseCell)
local ATTR_CELL = "app/ui/hero/cell/attr_cell"
local ATTR_CELL_PATH = "assets/prefabs/ui/hero/cell/attr_cell.prefab"

function AttrNodeCell:init()
	local uiMap = self:getUIMap()

	self.txTitle = uiMap["total_node.tx_title"]
	self.itemsRoot = uiMap["total_node.items"]
end

function AttrNodeCell:refresh(heroEntity, node)
	if node == GConst.HeroConst.ATTR_SHOW_TOTAL then
		self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_13))
	elseif node == GConst.HeroConst.ATTR_SHOW_BASE then
		self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_14))
	elseif node == GConst.HeroConst.ATTR_SHOW_SKIN then
		self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_17))
	end

	self.attrCount = 0
	for index, attr in ipairs(node) do
		if self:isShowAttr(heroEntity, node, attr) then
			self.attrCount = self.attrCount + 1
			CellManager:loadCellAsync(ATTR_CELL_PATH, ATTR_CELL, self.itemsRoot, function(cell)
				cell:refresh(heroEntity, node, attr)
			end)
		end
	end
end

-- 是否显示属性项
function AttrNodeCell:isShowAttr(heroEntity, node, attr)
	if node == GConst.HeroConst.ATTR_SHOW_SKIN then
		return DataManager.SkinData:hasAttr(heroEntity, attr[heroEntity:getMatchType()])
	end

	return true
end

--获取节点显示属性个数
function AttrNodeCell:getShowAttrCount()
	return self.attrCount
end

return AttrNodeCell