local EquipListCell = class("EquipListCell", BaseCell)

function EquipListCell:init()
	local uiMap = self.baseObject:genAllChildren()
	self.equipCell = uiMap["cell.equip_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.EQUIP_CELL)
	self.nameTx = uiMap["cell.name_tx"]
	self.powerTx = uiMap["cell.power_node.power_tx"]
	self.wearBtn = uiMap["cell.wear_btn"]
	self.wearBtnIcon = uiMap["cell.wear_btn.bg.icon"]
	self.wearBtnBg = uiMap["cell.wear_btn.bg"]
	self.wearBtnTx = uiMap["cell.wear_btn.text"]
	self.powerNode = uiMap["cell.power_node"]
	self.powerDescTx = uiMap["cell.power_node.power_desc_tx"]
	self.wearBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_30))
	self.powerDescTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_HERO_DESC_10))
	GFunc.setTextLength(self.powerDescTx)

	self.wearBtn:addClickListener(function()
		ModuleManager.EquipManager:onEquipWearReq(self.slotId, {self.equipEntity:getUid()})
	end)
end

function EquipListCell:refresh(equipEntity, slotId, equipPart)
	self.equipEntity = equipEntity
	self.slotId = slotId
	self.equipPart = equipPart
	self.nameTx:setText(equipEntity:getNameQltColor())
	self.powerTx:setText(equipEntity:getPower())
	self.equipCell:refresh(equipEntity, slotId)
	GFunc.setTextLength(self.powerTx)
	self.powerNode:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT):RefreshLayout()

	local useHero = DataManager.EquipData:getEquipUseHero(equipEntity:getUid())
	if useHero then
		local heroEntity = DataManager.HeroData:getHeroById(useHero)
		self.wearBtnBg:setActive(true)
		self.wearBtnBg:setSprite(GConst.ATLAS_PATH.ICON_ITEM, GConst.FRAME_QLT[heroEntity:getQlt()])
		self.wearBtnIcon:setSprite(GConst.ATLAS_PATH.ICON_HERO, heroEntity:getIcon())
	else
		self.wearBtnBg:setActive(false)
	end
end

return EquipListCell