local ChooseRewardTips = class("ChooseRewardTips", BaseUI)

function ChooseRewardTips:ctor(params)
	self.strTitle = params.title
	self.strDesc = params.desc
	self.chooseRewards = params.rewards
	self.chooseCallback = params.callback
end

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

function ChooseRewardTips:getPrefabPath()
	return "assets/prefabs/ui/tips/choose_reward_tips.prefab"
end

function ChooseRewardTips:isFullScreen()
    return false
end

function ChooseRewardTips:onClose()
    if self.chooseCallback and self.selectIndex then
        self.chooseCallback(self.selectIndex)
    end
end

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

    self.txDesc = uiMap["choose_reward_tips.content.tx_desc"]
    self.txTitle = uiMap["choose_reward_tips.content.tx_title"]
    self.scrollRectComp = uiMap["choose_reward_tips.content.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
    self.btnClose = uiMap["choose_reward_tips.content.btn_close"]
    self.rewardCell = uiMap["choose_reward_tips.content.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)

    self.selectIndex = nil
    self.txTitle:setText(self.strTitle or I18N:getGlobalText(I18N.GlobalConst.HERO_CARD_TIPS_DESC))
    self.txDesc:setText(self.strDesc or I18N:getGlobalText(I18N.GlobalConst.HERO_CARD_TIPS_DESC))
    self.rewardCell:refreshByChoose()
    self:initScrollRect()

    self.btnClose:addClickListener(function()
        self:closeUI()
    end)
end

function ChooseRewardTips:initScrollRect()
    self.scrollRectComp:addInitCallback(function()
		return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
	end)
	self.scrollRectComp:addRefreshCallback(function(index, cell)
		cell:refreshByConfig(self.chooseRewards[index])
        cell:showSelect(index == self.selectIndex)
		cell:addClickListener(function()
            self:onSelectReward(index)
        end)
	end)
    self.scrollRectComp:clearCells()
    self.scrollRectComp:refillCells(#self.chooseRewards)
end

function ChooseRewardTips:onSelectReward(index)
    self.selectIndex = index
    self.rewardCell:refreshByConfig(self.chooseRewards[self.selectIndex])
    self.scrollRectComp:updateAllCell()
end

return ChooseRewardTips