local TournArenaGiftComp = class("TournArenaGiftComp", LuaComponent)

function TournArenaGiftComp:init()
    local uiMap = self:getUIMap()
    self.scrollrectComp = uiMap["gift_panel.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)

    self.scrollrectComp:addInitCallback(function()
		return "app/ui/activity/tourn_arena/cell/tourn_arena_gift_cell"
	end)
	self.scrollrectComp:addRefreshCallback(function(index, cell)
		cell:refresh(self.giftList[index].id)
	end)

    self:bind(DataManager.TournArenaData, "isDirty", function()
        self:refresh()
	end)
    self:bind(DataManager.ShopData, "isDirty", function()
        self:refresh()
	end)
end

function TournArenaGiftComp:refresh()
    self.giftList = DataManager.TournArenaData:getGiftIdsSort()
    self.scrollrectComp:clearCells()
	self.scrollrectComp:refillCells(#self.giftList)
end

return TournArenaGiftComp