local BuyGemUI = class("BuyGemUI", BaseUI)

local GEM_CELL = "app/ui/shop/cell/gem_cell"

function BuyGemUI:isFullScreen()
	return false
end

function BuyGemUI:showCommonBG()
	return false
end

function BuyGemUI:ctor()
end

function BuyGemUI:getPrefabPath()
	return "assets/prefabs/ui/shop/buy_gem_ui.prefab"
end

function BuyGemUI:onLoadRootComplete()
	local uiMap = self.root:genAllChildren()
	self.mask = uiMap["buy_gem_ui.mask"]
	self.txTitle = uiMap["buy_gem_ui.content.tx_title"]
	self.btnClose = uiMap["buy_gem_ui.content.btn_close"]
	self.scrollrect = uiMap["buy_gem_ui.content.content.scrollrect"]

	self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.MALL_DESC_6))

	self.mask:addClickListener(function()
		self:closeUI()
	end)
	self.btnClose:addClickListener(function()
		self:closeUI()
	end)
	self:bind(DataManager.ShopData, "isDirty", function()
		self:onRefresh()
	end)
end

function BuyGemUI:onRefresh()
	local count = #ConfigManager:getConfig("mall_treasure")
    if not self.scrollRect then
        self.scrollRect = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
        self.scrollRect:addInitCallback(function()
            return GEM_CELL
        end)
        self.scrollRect:addRefreshCallback(function(index, cell)
            cell:refresh(index)
        end)
    end
    if self.scrollRect:getTotalCount() == nil or self.scrollRect:getTotalCount() <= 0 then
		self.scrollRect:refillCells(count)
    elseif self.scrollRect:getTotalCount() ~= count then
		self.scrollRect:clearCells()
		self.scrollRect:refillCells(count)
	else
		self.scrollRect:updateAllCell()
	end
end

return BuyGemUI