local GiftRewardCell = class("GiftRewardCell", BaseCell)

function GiftRewardCell:init()
	local uiMap = self.baseObject:genAllChildren()
    self.bg = uiMap["gift_reward_cell.bg"]
	self.icon = uiMap["gift_reward_cell.icon"]
	self.fragmenImg = uiMap["gift_reward_cell.fragment"]
	self.numTx = uiMap["gift_reward_cell.num"]
	
	self.baseObject:addClickListener(function()
		if self.clickCallback then
			self.clickCallback()
		end
	end)
end

function GiftRewardCell:refreshByConfig(reward)
    local id = reward.id
    local num = reward.num
	local heroCfgInfo = ConfigManager:getConfig("hero")[id]
    if heroCfgInfo then
        local qlt = heroCfgInfo.qlt
        self.bg:setSprite(GConst.ATLAS_PATH.SHOP, "shop_gift_bg_" .. qlt)
        self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, tostring(heroCfgInfo.icon))
        self.fragmenImg:setVisible(true)
        self.numTx:setText("X" .. tostring(num))
    else
        local itemCfgInfo = ConfigManager:getConfig("item")[id]
        self.bg:setSprite(GConst.ATLAS_PATH.SHOP, "shop_gift_bg")
        self.icon:setSprite(GConst.ATLAS_PATH.ICON_ITEM, tostring(itemCfgInfo.icon))
        self.fragmenImg:setVisible(false)
        self.numTx:setText(num)
    end
    self:addClickListener(function()
        ModuleManager.TipsManager:showRewardTips(reward.id, reward.type, self.baseObject)
    end)
end

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

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

return GiftRewardCell
