local ArenaGradingRewardUI = class("ArenaGradingRewardUI", BaseUI)

function ArenaGradingRewardUI:isFullScreen()
	return true
end

function ArenaGradingRewardUI:showCommonBG()
	return false
end

function ArenaGradingRewardUI:getPrefabPath()
	return "assets/prefabs/ui/arena/arena_grading_reward_ui.prefab"
end

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

function ArenaGradingRewardUI:ctor()
end

function ArenaGradingRewardUI:onCover()
end

function ArenaGradingRewardUI:onReshow()
end

function ArenaGradingRewardUI:onClose()
end

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

	self.scrollrectComp = uiMap["arena_grading_reward_ui.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
	self.scrollrectContent = uiMap["arena_grading_reward_ui.scrollrect.viewport.content"]
	self.bannerCanvas = uiMap["arena_grading_reward_ui.banner"]:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS)
	self.btnClose = uiMap["arena_grading_reward_ui.banner.btn_close"]
	self.txTips = uiMap["arena_grading_reward_ui.banner.tx_tips"]

	self.bannerCanvas.overrideSorting = true
	self.bannerCanvas.sortingOrder = self:getUIOrder() + GConst.UI_EFFECT_ORDER.LEVEL5
	
	local cfg = DataManager.ArenaData:getGradingRewardCfg()
	self.txTips:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_39))
	self.scrollrectComp:addInitCallback(function()
		return "app/ui/arena/cell/arena_grading_reward_cell"
	end)
	self.scrollrectComp:addRefreshCallback(function(index, cell)
		cell:setUI(self)
		cell:refresh(index)
	end)
	self.scrollrectComp:clearCells()
	self.scrollrectComp:refillCells(#cfg)
	-- 处理进入定位
	self.scrollrectContent:setActive(false)
	self:performWithDelayGlobal(function()
		-- self.scrollrectComp:moveToIndex(DataManager.ArenaData:getCurTargetIndex())
		local posY = -DataManager.ArenaData:getCurTargetPosY()
		local temp = -self.scrollrectComp.baseObject:fastGetSizeDeltaY() / 2
		Logger.logHighlight(posY.. "/"..temp)
		if posY + temp <= 0 then
			posY = posY + temp
		end
		Logger.logHighlight(posY)
		self.scrollrectContent:setAnchoredPositionY(posY)
		self.scrollrectContent:setActive(true)
	end, 0.01)

    self.btnClose:addClickListener(function()
		self:closeUI()
	end)
	self:bind(DataManager.ArenaData, "isDirty", function()
        self:onRefresh()
    end)
end

function ArenaGradingRewardUI:onRefresh()
	self.scrollrectComp:updateAllCell()
end

return ArenaGradingRewardUI