local BagMainUI = class("BagMainUI", BaseUI)

function BagMainUI:isFullScreen()
	return false
end

function BagMainUI:getPrefabPath()
	return "assets/prefabs/ui/bag/bag_main_ui.prefab"
end

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

function BagMainUI:ctor(parmas)
end

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

	uiMap["bag_main_ui.bg.close_btn"]:addClickListener(function()
		self:closeUI()
	end)

	self.titleTx = uiMap["bag_main_ui.bg.title_tx"]
	self.btnTxs = {I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_4), I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_16)}
	-- self.pageBtns = {}
	-- self.pageBtnTxs = {}
	-- self.pageBtnLocks = {}
	-- self.pageRedImgs = {}
	-- for i = 1, 2 do
	-- 	self.pageBtns[i] = uiMap["bag_main_ui.bg.btns.page_btn_" .. i]
	-- 	self.pageBtnTxs[i] = uiMap["bag_main_ui.bg.btns.page_btn_" .. i .. ".text"]
	-- 	self.pageBtnLocks[i] = uiMap["bag_main_ui.bg.btns.page_btn_" .. i .. ".lock_img"]
	-- 	self.pageRedImgs[i] = uiMap["bag_main_ui.red_node.red_img_" .. i]
	-- 	-- if self.pageBtnLocks[i] then
	-- 	-- 	self.pageBtnLocks[i]:setActive(not self:getIsOpen(i))
	-- 	-- end
	-- 	self.pageBtns[i] :addClickListener(function()
	-- 		if not self:getIsOpen(i) or self.page == i then
	-- 			return
	-- 		end
	-- 		self.page = i
	-- 		self:onRefresh()
	-- 	end)
	-- end

	self.scrollrect = uiMap["bag_main_ui.bg.scrollrect"]
	self.scrollRectComp = uiMap["bag_main_ui.bg.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
    self.scrollRectComp:addInitCallback(function()
		return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
	end)
	self.scrollRectComp:addRefreshCallback(function(index, cell)
		cell:refreshByEntity(self.list[index])
		cell:addClickListener(function()
			ModuleManager.TipsManager:showRewardTips(self.list[index]:getId(), self.list[index]:getType(), cell.baseObject, nil, nil, true)
		end)
	end)
    self.scrollRectComp:clearCells()

	self:bind(DataManager.BagData.ItemData, "dirty", function()
		self:onRefresh()
	end)
end

function BagMainUI:onRefresh()
	self:initList()
	-- self:refreshPageBtn()
	self:refreshScrollrect()

	self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.BAG_DESC_1))
end

function BagMainUI:initList()
	self.list = DataManager.BagData:getItemList()
end

-- 刷新标签红点
-- function BagMainUI:refreshPageBtn()
-- 	for i = 1, 2 do
-- 		self.pageBtns[i]:setActive(false)
-- 		if self.page == i then
-- 			self.pageBtns[i]:setSprite(GConst.ATLAS_PATH.COMMON, "common_tab_1")
-- 			self.pageBtnTxs[i]:setText(self.btnTxs[i])
-- 		else
-- 			self.pageBtns[i]:setSprite(GConst.ATLAS_PATH.COMMON, "common_tab_2")
-- 			self.pageBtnTxs[i]:setText("<color=#72778C>" .. self.btnTxs[i] .. "</color>")
-- 		end
-- 		-- self.pageRedImgs[i]:setActive(self.heroEntity:showRedPoint(i))
-- 		self.pageRedImgs[i]:setActive(false)
-- 	end
-- end

function BagMainUI:refreshScrollrect()
	self.scrollRectComp:refillCells(#self.list)
end

return BagMainUI