local StarCell = class("StarCell", BaseCell)

function StarCell:init()
	local uiMap = self:getUIMap()
	self.starBg = uiMap["cell.star_bg"]
	self.descTx = uiMap["cell.desc_tx"]
	self.starImgs = {}
	for i = 1, 5 do
		self.starImgs[i] = uiMap["cell.star_bg.star_img_" .. i]
	end

	-- self:addClickListener(function()
	-- 	EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.SKIN_SELECT, self.skinId)
	-- end)
end

function StarCell:refresh(heroEntity, idx)
	self.heroEntity = heroEntity
	if not self.heroEntity then
		return
	end

	local star = self.heroEntity:getStar()
	local starType = math.ceil(idx / 5)
	for i, v in ipairs(self.starImgs) do
		local star = (idx - 1)%5 + 1
		if i <= star then
			v:setActive(true)
			v:setSprite(GFunc.getStarImg(starType))
		else
			v:setActive(false)
		end
	end
	if idx <= star then
		self.baseObject:setSprite(GConst.ATLAS_PATH.COMMON, "common_board_quality_3")
	else
		self.baseObject:setSprite(GConst.ATLAS_PATH.COMMON, "common_board_quality_2")
	end
	self.starBg:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT):RefreshLayout()

	local attr = heroEntity:getStarAttrCfg(idx)
	local descTx = GFunc.getAttrDesc(attr.type, attr.num)
	if not table.containValue(GConst.MATCH_ALL_ATKP_NAME, attr.type) then
		descTx = heroEntity:getName() .. descTx
	end
	self.descTx:setText(descTx)
end

return StarCell