local TalentInfoUI = class("TalentInfoUI", BaseUI)

local TALENT_CELL = "app/ui/talent/cell/talent_cell"

function TalentInfoUI:ctor(parmas)
	parmas = parmas or {}
	self.id = parmas.id or 1
end

function TalentInfoUI:isFullScreen()
    return false
end

function TalentInfoUI:getPrefabPath()
    return "assets/prefabs/ui/talent/talent_info_ui.prefab"
end

function TalentInfoUI:onLoadRootComplete()
    local uiMap = self.root:genAllChildren()
	self.root:addClickListener(function()
		self:closeUI()
	end)

	self.talentCell = uiMap["talent_info_ui.node.talent_cell"]:addLuaComponent(TALENT_CELL)
	self.descTx = uiMap["talent_info_ui.desc_tx"]
	self.leftArrowBtn = uiMap["talent_info_ui.left_arrow_btn"]
	self.rightArrowBtn = uiMap["talent_info_ui.right_arrow_btn"]
	local continue = uiMap["talent_info_ui.continue"]
	continue:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_TO_CONTINUE))

	self.leftArrowBtn:addClickListener(function()
		self.idx  = self.idx - 1
		self:onRefresh()
	end)
	self.rightArrowBtn:addClickListener(function()
		self.idx  = self.idx + 1
		self:onRefresh()
	end)
	self.list = DataManager.TalentData:getActiveList()
	for i, cfg in ipairs(self.list) do
		if cfg.id == self.id then
			self.idx = i
			break
		end
	end
end

-- TalentData.SKILL_REFESH_ID = 9
-- TalentData.HP_RESTORE_ID = 10
-- TalentData.SELECT_SKILL_ID = 11
-- TalentData.ICON_ADD_ID = 12
-- TalentData.EXP_ADD_ID = 16

function TalentInfoUI:onRefresh()
	self.id = self.list[self.idx].id
	self.talentCell:refresh(self.id, self.list[self.idx])
	self.leftArrowBtn:setActive(self.idx > 1 and #self.list ~= 1)
	self.rightArrowBtn:setActive(self.idx < #self.list and #self.list ~= 1)
	local attr, num = DataManager.TalentData:getAttrById(self.id)
	local str = I18N:getText("talent", self.id, "desc")
	if attr and #attr > 0 then
		str = str .. GFunc.getFinalAttrValue(attr[1].type, attr[1].num)
	elseif self.id == DataManager.TalentData.SELECT_SKILL_ID then
	elseif self.id == DataManager.TalentData.SKILL_REFESH_ID then
		str = str .. (num or 0)
	elseif self.id == DataManager.TalentData.HP_RESTORE_ID then
		str = str .. (num or 0) // GConst.DEFAULT_FACTOR
	else
		str = str .. (num or 0) // 100 .. "%"
	end
	self.descTx:setText(str)
end

return TalentInfoUI