local TalentCell = class("TalentCell", BaseCell)

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

	self.animator = self.baseObject:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR)
	self.bg1 = uiMap["talent_cell.bg1"]
	self.bg = uiMap["talent_cell.bg"]
	self.descTx1 = uiMap["talent_cell.desc_tx_1"]
	self.descTx2 = uiMap["talent_cell.desc_tx_2"]
	self.animator.enabled = false

	self.baseObject:addClickListener(function()
		local lv = DataManager.TalentData:getLevels(self.idx)
		if lv <= 0 then
			return
		end
		local parmas = {}
		parmas.id = self.idx
		ModuleManager.TalentManager:showInfoUI(parmas)
	end)
end

function TalentCell:refresh(idx, cfg, showAni)
	self.idx = idx
	self.bg1:setSprite(GConst.ATLAS_PATH.ICON_TALENT, "talent_" .. idx)
	self.descTx1:setText(I18N:getText("talent", idx, "name"))
	local lv = DataManager.TalentData:getLevels(idx)
	self.descTx2:setText("Lv." .. lv)
	if showAni then
		self.bg:setActive(true)
		self.bg:setSprite(GConst.ATLAS_PATH.ICON_TALENT, "talent_b_" .. cfg.qlt)
		self.animator.enabled = true
		self.animator:SetTrigger("t_open")
	elseif lv <= 0 then
		self.bg:setActive(true)
		self.bg:setSprite(GConst.ATLAS_PATH.ICON_TALENT, "talent_b_0")
	else
		self.bg:setActive(false)
	end
end

function TalentCell:setActive(active)
	self.baseObject:setActive(active)
end

function TalentCell:setLocalScale(scaleX, scaleY, scaleZ)
	self.baseObject:setLocalScale(scaleX, scaleY, scaleZ)
end

return TalentCell