local HeroSkillInfoUI = class("HeroSkillInfoUI", BaseUI)

function HeroSkillInfoUI:isFullScreen()
	return false
end

function HeroSkillInfoUI:getPrefabPath()
	return "assets/prefabs/ui/hero/hero_skill_info_ui_2.prefab"
end

function HeroSkillInfoUI:onPressBackspace()
	self:closeUI()
end

function HeroSkillInfoUI:ctor(parmas)
	self.heroEntity = parmas.heroEntity
	self.buffId = parmas.buffId
end

function HeroSkillInfoUI:onLoadRootComplete()
	local uiMap = self.root:genAllChildren()

	self.root:addClickListener(function()
		self:closeUI()
	end)

	uiMap["hero_skill_info_ui_2.content.btn_close"]:addClickListener(function()
		self:closeUI()
	end)

	self.descTx = uiMap["hero_skill_info_ui_2.content.desc_tx"]
	self.skillIcon = uiMap["hero_skill_info_ui_2.content.skill_icon"]
	self.icon = uiMap["hero_skill_info_ui_2.content.skill_icon.icon"]
	self.skillDescTx = uiMap["hero_skill_info_ui_2.content.skill_icon.desc_tx"]
	self.buffNode = uiMap["hero_skill_info_ui_2.content.buff_node"]
	self.content = uiMap["hero_skill_info_ui_2.content"]
	self.line = uiMap["hero_skill_info_ui_2.content.line_1"]

	self.buffImgs = {}
	self.buffTxs = {}
	for i = 1, 2 do
		self.buffImgs[i] = uiMap["hero_skill_info_ui_2.content.buff_node.buff_img_" .. i]
		self.buffTxs[i] = uiMap["hero_skill_info_ui_2.content.buff_node.buff_tx_" .. i]
	end
end

function HeroSkillInfoUI:onRefresh()
	self.height = 300
	self:refreshSkillIcon()
	self:refreshSkillBuff()
	self.height = self.height + 36
	self.content:setSizeDeltaY(self.height)
end

function HeroSkillInfoUI:refreshSkillIcon()
	local skillId = self.heroEntity:getBaseSkill()
	self.skillIcon:setSprite(GConst.ATLAS_PATH.HERO, ModuleManager.HeroManager:getSkillBg(skillId))
	self.icon:setSprite(GConst.ATLAS_PATH.ICON_SKILL, ModuleManager.HeroManager:getSkillIcon(skillId))
	self.descTx:setText(ModuleManager.HeroManager:getSkillDesc(skillId))
end

function HeroSkillInfoUI:refreshSkillBuff()
	if not self.buffId then
		self.buffNode:setActive(false)
		self.line:setActive(false)
		self.height = 300
		return
	else
		local posY = -20
		self.buffNode:setActive(true)
		self.line:setActive(true)
		self.buffNode:setAnchoredPositionY(-self.height)
		for i = 1, 2 do
			if self.buffId[i] then
				self.buffImgs[i]:setActive(true)
				self.buffTxs[i]:setActive(true)
				local buffInfo = ConfigManager:getConfigWithOtherKey("buff", "name")[self.buffId[i]]
				self.buffTxs[i]:setText(I18N:getTextWithOtherKey("buff", "name", buffInfo.name, "tips_desc"))
				self.buffImgs[i]:setSprite(GConst.ATLAS_PATH.ICON_BUFF, buffInfo.icon)
				self.buffImgs[i]:setAnchoredPositionY(posY - 20)
				self.buffTxs[i]:setAnchoredPositionY(posY - 8)

				local meshProComp = self.buffTxs[i]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
				local contentHeight = meshProComp.preferredHeight
				posY = posY - contentHeight - 10
			else
				self.buffImgs[i]:setActive(false)
				self.buffTxs[i]:setActive(false)
			end
		end
		self.height = self.height - posY
	end
end

return HeroSkillInfoUI