local CollectionRewardUI = class("CollectionRewardUI", BaseUI)

function CollectionRewardUI:isFullScreen()
	return true
end

function CollectionRewardUI:showCommonBG()
	return false
end

function CollectionRewardUI:getPrefabPath()
	return "assets/prefabs/ui/collection/collection_reward_ui.prefab"
end

function CollectionRewardUI:onPressBackspace()
	self:closeUI()
end

function CollectionRewardUI:ctor(params)
    self.collectType = params
end

function CollectionRewardUI:onCover()
end

function CollectionRewardUI:onReshow()
end

function CollectionRewardUI:onClose()
end

function CollectionRewardUI:onLoadRootComplete()
	local uiMap = self.root:genAllChildren()

    self.scrollrectComp = uiMap["collect_reward_ui.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
    uiMap["collect_reward_ui.banner.btn_close"]:addClickListener(function()
		self:closeUI()
	end)
end

function CollectionRewardUI:onRefresh()
	local datas = DataManager.CollectionData:getRewardList()
	self.scrollrectComp:addInitCallback(function()
		return "app/ui/collection/cell/collection_reward_cell"
	end)
	self.scrollrectComp:addRefreshCallback(function(index, cell)
		cell:refresh(self.collectType, index)
	end)
	self.scrollrectComp:clearCells()
	self.scrollrectComp:refillCells(#datas)
    local selectIdx = DataManager.CollectionData:getCurTargetId()
    if selectIdx - 2 >= 0 then
        selectIdx = selectIdx - 2
    end
    self.scrollrectComp:moveToIndex(selectIdx)
end

return CollectionRewardUI