local GemCell = class("GemCell", BaseCell)

function GemCell:init()
	local uiMap = self:getUIMap()
	self.content = uiMap["gem_cell.content"]
	self.img = uiMap["gem_cell.content.img"]
	self.txReward = uiMap["gem_cell.content.tx_reward"]
	self.txPrice = uiMap["gem_cell.content.tx_price"]
	self.tag = uiMap["gem_cell.content.tag"]
	self.txDouble = uiMap["gem_cell.content.tag.tx_double"]
	self.imgIcon = uiMap["gem_cell.content.tag.img_icon"]
	self.txDoubleNum = uiMap["gem_cell.content.tag.tx_num"]

	self.baseObject:addClickListener(function()
		local isDouble = DataManager.PaymentData:getGemStoreDoubleCount(self.id) > 0
		local doubleType = ""
		if isDouble then
			doubleType = BIReport.PAY_DOUBLE.DOUBLED
		else
			doubleType = BIReport.PAY_DOUBLE.NORMAL
		end
		ModuleManager.ShopManager:onBuyGemGift(self.id, doubleType)
	end)
end

function GemCell:refresh(id)
	self.id = id
	local cfg = DataManager.ShopData:getGemConfig(self.id)
	local reward = cfg.reward[1]
	if self.id >= 6 then
		self.img:setSprite(GConst.ATLAS_PATH.UI_SHOP, "shop_diamond_6")
	else
		self.img:setSprite(GConst.ATLAS_PATH.UI_SHOP, "shop_diamond_" .. self.id)
	end
	self.txReward:setText(GFunc.getRewardNum(reward))
	local rechargeId = cfg.recharge_id
	local priceStr = nil
	if rechargeId and ConfigManager:getConfig("recharge")[rechargeId] then
		priceStr = GFunc.getFormatPrice(rechargeId)
	end
	self.txPrice:setText(priceStr)

	local count  = DataManager.PaymentData:getGemStoreDoubleCount(self.id)
	if count > 0 then
		self.tag:setActive(true)
		-- self.txReward:setAnchoredPositionY(-90)
		self.txDouble:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_21, count))
		self.txDoubleNum:setText("+" .. GFunc.getRewardNum(reward))
		-- GFunc.centerImgAndTx(self.imgIcon, self.txDoubleNum, 0)
	else
		self.tag:setActive(false)
		-- self.txReward:setAnchoredPositionY(-50)
	end
end

function GemCell:setVisible(visible, scale)
	self.baseObject:setVisible(visible, scale)
end

return GemCell