local WeightBoxTips = class("WeightBoxTips", BaseUI)

function WeightBoxTips:ctor(params)
	self.itemId = params.itemId
end

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

function WeightBoxTips:getPrefabPath()
	return "assets/prefabs/ui/tips/weight_box_tips.prefab"
end

function WeightBoxTips:isFullScreen()
	return false
end

function WeightBoxTips:onLoadRootComplete()
	local cfg = ConfigManager:getConfig("item")[self.itemId]
	if cfg == nil then
		return self:closeUI()
	end
	self.dropIds = {}
	if cfg.hero_drop then
		self.dropIds = cfg.hero_drop
	elseif cfg.box_drop then
		for _, item in ipairs(cfg.box_drop) do
			table.insert(self.dropIds, item)
		end
	end
	local uiMap = self.root:genAllChildren()
	self.uiMap = uiMap
	local itemQlt = cfg.qlt
	if itemQlt < 1 then
		itemQlt = 1
	elseif itemQlt > 4 then
		itemQlt = 4
	end
	local bgQlt = uiMap["weight_box_tips.title_bg_img.bg_qlt"]
	bgQlt:setVisible(false)
	bgQlt:setTexture("assets/arts/textures/background/shop/shop_card_bg_" .. itemQlt .. ".png", function()
		bgQlt:setVisible(true)
	end)
	uiMap["weight_box_tips.title_bg_img.card"]:setSprite(GConst.ATLAS_PATH.ICON_ITEM, cfg.icon)
	uiMap["weight_box_tips.title_bg_img.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_CARD_TIPS_DESC))
	uiMap["weight_box_tips.title_bg_img.title_text"]:setText(I18N:getText("item", self.itemId, "name"))
	uiMap["weight_box_tips.title_bg_img.close_btn"]:addClickListener(function()
		self:closeUI()
	end)

	if cfg.type == GConst.ItemConst.ITEM_TYPE.EPIC_HERO_FRAMENT then
		uiMap["weight_box_tips.title_bg_img.desc"]:setText(I18N:getText("item", self.itemId, "desc"))
	end

	self:initScrollRect()
end

function WeightBoxTips:initScrollRect()
	local scrollRectComp = self.uiMap["weight_box_tips.title_bg_img.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
	scrollRectComp:addInitCallback(function()
		return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
	end)
	scrollRectComp:addRefreshCallback(function(index, cell)
		cell:refreshByConfig(self.dropIds[index])
	end)
	scrollRectComp:clearCells()
	scrollRectComp:refillCells(#self.dropIds)
end

return WeightBoxTips