local GemSellCell = class("GemSellCell", BaseCell)

function GemSellCell:init()
	local uiMap = self.baseObject:genAllChildren()
	local titleTx = uiMap["gem_sell_cell.title_bg.text"]
	titleTx:setText(ModuleManager.ItemManager:getItemName(GConst.ItemConst.ITEM_ID_GEM))

	self.cells = {}
	self.cellHeight = 0
	local cellHeight = nil
	local cfg = DataManager.ShopData:getMallTreasureConfig() -- 审核模式读取另一张表
	for i = 1, 19 do -- 正常9个 提审19个
		local cell = uiMap["gem_sell_cell.cell_" .. i]
		if cellHeight == nil then
			local w, h = cell:fastGetSizeDelta()
			cellHeight = h
		end
		local id = i
		if CS.BF.BFMain.IsShenhe then
			id = i + 1 -- 配置表结构约定
		end
		if cfg[id] then
			local cellComp = cell:addLuaComponent("app/ui/shop/cell/gem_cell")
			cell:setVisible(true)
			table.insert(self.cells, cellComp)
		else
			cell:setVisible(false)
		end
	end
	local totalCount = #self.cells
	if totalCount > 0 then
		self.cellHeight = self.cellHeight + (20 + cellHeight) * math.ceil(totalCount / 3) + 80
	end
end

function GemSellCell:refresh()
	local cfg = DataManager.ShopData:getMallTreasureConfig()
	for idx, v in ipairs(self.cells) do
		local id = idx
		if CS.BF.BFMain.IsShenhe then
			id = idx + 1 -- 配置表结构约定
			v:refresh(id, cfg[id])
		else
			v:refresh(id, cfg[id])
		end
	end
end

function GemSellCell:getCellHeight()
	return self.cellHeight
end

function GemSellCell:getIsOpen()
	return true
end

function GemSellCell:setVisible(visible)
	self.baseObject:setVisible(visible)
end

return GemSellCell