local GrowthFundRewardCell = class("GrowthFundRewardCell", BaseCell)

function GrowthFundRewardCell:init()
	local uiMap = self:getUIMap()
	self.bg = uiMap["fund_reward_cell.bg"]
	self.icon = uiMap["fund_reward_cell.icon"]
	self.numTx = uiMap["fund_reward_cell.num"]
	self.check = uiMap["fund_reward_cell.check"]
	self.fragment = uiMap["fund_reward_cell.fragment"]
	self.light = uiMap["fund_reward_cell.light"]
	self.lock = uiMap["fund_reward_cell.lock"]
	self.baseObject:addClickListener(function()
		if self.clickCallback then
			self.clickCallback()
		elseif self.rewardId ~= nil then
			ModuleManager.TipsManager:showRewardTips(self.rewardId, self.rewardType, self.baseObject)
		end
	end)
end

function GrowthFundRewardCell:refresh(reward, step, isLock, showCheck)
	if step == 0 then
		self.bg:setSprite(GConst.ATLAS_PATH.FUND, "fund_bg_5")
	elseif step == 1 then
		self.bg:setSprite(GConst.ATLAS_PATH.FUND, "fund_bg_2")
	elseif step == 2 then
		self.bg:setSprite(GConst.ATLAS_PATH.FUND, "fund_bg_3")
	else
		self.bg:setSprite(GConst.ATLAS_PATH.FUND, "fund_bg_4")
	end
	if isLock then
		self.lock:setVisible(true)
		self.light:setVisible(false)
	else
		self.lock:setVisible(false)
		if step == 0 or showCheck then
			self.light:setVisible(false)
		else
			self.light:setVisible(true)
		end
	end
	self.check:setVisible(showCheck == true)
	if reward.type == GConst.REWARD_TYPE.ITEM then
		self:_refreshItem(reward)
		self.rewardId = reward.id
		self.rewardType = reward.type
	else
		self.rewardId = nil
	end
end

function GrowthFundRewardCell:_refreshItem(item)
	local info = ConfigManager:getConfig("item")[item.id]
	if info == nil then
		return
	end
	self.numTx:setText(item.count or item.num)
	if info.type == GConst.ItemConst.ITEM_TYPE.HERO_FRAGMENT then
		local heroInfo = ConfigManager:getConfig("hero")[info.parameter]
		if heroInfo then
			self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, heroInfo.icon)
		else
			self.icon:setSprite(GConst.ATLAS_PATH.COMMON, "common_alpha")
		end
		self.fragment:setVisible(true)
	else
		self.icon:setSprite(GConst.ATLAS_PATH.ICON_ITEM, info.icon)
		self.fragment:setVisible(false)
	end
end

function GrowthFundRewardCell:setVisible(visible)
	self.baseObject:setActive(visible)
end

function GrowthFundRewardCell:setAnchoredPositionX(x)
	self.baseObject:setAnchoredPositionX(x)
end

function GrowthFundRewardCell:setTouchEnable(enable)
	self.baseObject:setTouchEnable(enable)
end

function GrowthFundRewardCell:addClickListener(callback)
	self.clickCallback = callback
end

return GrowthFundRewardCell