local BoxLevelUpUI = class("BoxLevelUpUI", BaseUI)

function BoxLevelUpUI:ctor(params)
    params = params or {}
    self.level = params.level or DataManager.SummonData:getSummonLevel()
end

function BoxLevelUpUI:isFullScreen()
    return true
end

function BoxLevelUpUI:getPrefabPath()
    return "assets/prefabs/ui/shop/box_level_up_ui.prefab"
end

function BoxLevelUpUI:onLoadRootComplete()
    self.uiMap = self.root:genAllChildren()
	self.uiMap["box_level_up_ui.mask"]:addClickListener(function()
		self:closeUI()
	end)

	self.titleTx = self.uiMap["box_level_up_ui.title.text"]
	self.lvTx = self.uiMap["box_level_up_ui.lv_up.text"]
    
	self.box1Node = self.uiMap["box_level_up_ui.box_1"]
    self.box1Add1Node = self.uiMap["box_level_up_ui.box_1.add_node_1"]
    self.box1Add1ItemCell = CellManager:addCellComp(self.uiMap["box_level_up_ui.box_1.add_node_1.item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
    self.box1Add1Text = self.uiMap["box_level_up_ui.box_1.add_node_1.text"]
    self.box1Add2Node = self.uiMap["box_level_up_ui.box_1.add_node_2"]
    self.box1Add2ItemCell = CellManager:addCellComp(self.uiMap["box_level_up_ui.box_1.add_node_2.item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
    self.box1Add2Text = self.uiMap["box_level_up_ui.box_1.add_node_2.text"]
    self.box1Desc = self.uiMap["box_level_up_ui.box_1.none_text"]
    self.box1Desc:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_4)) -- 无额外奖励加成

	self.box2Node = self.uiMap["box_level_up_ui.box_2"]
    self.box2Add1Node = self.uiMap["box_level_up_ui.box_2.add_node_1"]
    self.box2Add1ItemCell = CellManager:addCellComp(self.uiMap["box_level_up_ui.box_2.add_node_1.item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
    self.box2Add1Text = self.uiMap["box_level_up_ui.box_2.add_node_1.text"]
    self.box2Add2Node = self.uiMap["box_level_up_ui.box_2.add_node_2"]
    self.box2Add2ItemCell = CellManager:addCellComp(self.uiMap["box_level_up_ui.box_2.add_node_2.item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
    self.box2Add2Text = self.uiMap["box_level_up_ui.box_2.add_node_2.text"]
    self.box2Desc = self.uiMap["box_level_up_ui.box_2.none_text"]
    self.box2Desc:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_4)) -- 无额外奖励加成

    self.box3Node = self.uiMap["box_level_up_ui.box_3"]
    self.box3Add1Node = self.uiMap["box_level_up_ui.box_3.add_node_1"]
    self.box3Add1ItemCell = CellManager:addCellComp(self.uiMap["box_level_up_ui.box_3.add_node_1.item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
    self.box3Add1Text = self.uiMap["box_level_up_ui.box_3.add_node_1.text"]
    self.box3Add2Node = self.uiMap["box_level_up_ui.box_3.add_node_2"]
    self.box3Add2ItemCell = CellManager:addCellComp(self.uiMap["box_level_up_ui.box_3.add_node_2.item_cell"], GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
    self.box3Add2Text = self.uiMap["box_level_up_ui.box_3.add_node_2.text"]
    self.box3Desc = self.uiMap["box_level_up_ui.box_3.none_text"]
    self.box3Desc:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_4)) -- 无额外奖励加成

    self.closeTx = self.uiMap["box_level_up_ui.close_tx"]

    self:refresh()
end

function BoxLevelUpUI:refresh()
    self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_6)) -- 宝箱等级提升!
    self.lvTx:setText("Lv." .. tostring(self.level))
    self.closeTx:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_TO_CONTINUE)) -- 点击继续

    self.box1Add1Node:setVisible(false)
    self.box1Add2Node:setVisible(false)
    self.box1Desc:setVisible(false)

    self.box2Add1Node:setVisible(false)
    self.box2Add2Node:setVisible(false)
    self.box2Desc:setVisible(false)

    self.box3Add1Node:setVisible(false)
    self.box3Add2Node:setVisible(false)
    self.box3Desc:setVisible(false)

    local reward1 = DataManager.SummonData:getSummonRewardByLv(GConst.SummonConst.SUMMON_TYPE.LV_1, self.level)
    local reward2 = DataManager.SummonData:getSummonRewardByLv(GConst.SummonConst.SUMMON_TYPE.LV_2, self.level)
    local reward3 = DataManager.SummonData:getSummonRewardByLv(GConst.SummonConst.SUMMON_TYPE.LV_3, self.level)

    local count = #reward1
    if count == 1 then
        self.box1Add1Node:setVisible(true)
        self.box1Add1ItemCell:refreshByCfg(reward1[1].id, 0)
        self.box1Add1ItemCell:setNum("")
        self.box1Add1ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward1[1].id, GConst.REWARD_TYPE.ITEM, self.box1Add1ItemCell:getBaseObject())
        end)
        self.box1Add1Text:setText("+" .. tostring(reward1[1].num))
    else
        self.box1Add1Node:setVisible(true)
        self.box1Add1ItemCell:refreshByCfg(reward1[1].id, 0)
        self.box1Add1ItemCell:setNum("")
        self.box1Add1ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward1[1].id, GConst.REWARD_TYPE.ITEM, self.box1Add1ItemCell:getBaseObject())
        end)
        self.box1Add1Text:setText("+" .. tostring(reward1[1].num))

        self.box1Add2Node:setVisible(true)
        self.box1Add2ItemCell:refreshByCfg(reward1[2].id, 0)
        self.box1Add2ItemCell:setNum("")
        self.box1Add2ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward1[2].id, GConst.REWARD_TYPE.ITEM, self.box1Add2ItemCell:getBaseObject())
        end)
        self.box1Add2Text:setText("+" .. tostring(reward1[2].num))
    end

    local count = #reward2
    if count == 1 then
        self.box2Add1Node:setVisible(true)
        self.box2Add1ItemCell:refreshByCfg(reward2[1].id, 0)
        self.box2Add1ItemCell:setNum("")
        self.box2Add1ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward2[1].id, GConst.REWARD_TYPE.ITEM, self.box2Add1ItemCell:getBaseObject())
        end)
        self.box2Add1Text:setText("+" .. tostring(reward2[1].num))
    else
        self.box2Add1Node:setVisible(true)
        self.box2Add1ItemCell:refreshByCfg(reward2[1].id, 0)
        self.box2Add1ItemCell:setNum("")
        self.box2Add1ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward2[1].id, GConst.REWARD_TYPE.ITEM, self.box2Add1ItemCell:getBaseObject())
        end)
        self.box2Add1Text:setText("+" .. tostring(reward2[1].num))

        self.box2Add2Node:setVisible(true)
        self.box2Add2ItemCell:refreshByCfg(reward2[2].id, 0)
        self.box2Add2ItemCell:setNum("")
        self.box2Add2ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward2[2].id, GConst.REWARD_TYPE.ITEM, self.box2Add2ItemCell:getBaseObject())
        end)
        self.box2Add2Text:setText("+" .. tostring(reward2[2].num))
    end

    local count = #reward3
    if count == 1 then
        self.box3Add1Node:setVisible(true)
        self.box3Add1ItemCell:refreshByCfg(reward3[1].id, 0)
        self.box3Add1ItemCell:setNum("")
        self.box3Add1ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward3[1].id, GConst.REWARD_TYPE.ITEM, self.box3Add1ItemCell:getBaseObject())
        end)
        self.box3Add1Text:setText("+" .. tostring(reward3[1].num))
    else
        self.box3Add1Node:setVisible(true)
        self.box3Add1ItemCell:refreshByCfg(reward3[1].id, 0)
        self.box3Add1ItemCell:setNum("")
        self.box3Add1ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward3[1].id, GConst.REWARD_TYPE.ITEM, self.box3Add1ItemCell:getBaseObject())
        end)
        self.box3Add1Text:setText("+" .. tostring(reward3[1].num))

        self.box3Add2Node:setVisible(true)
        self.box3Add2ItemCell:refreshByCfg(reward3[2].id, 0)
        self.box3Add2ItemCell:setNum("")
        self.box3Add2ItemCell:addClickListener(function()
            ModuleManager.TipsManager:showRewardTips(reward3[2].id, GConst.REWARD_TYPE.ITEM, self.box3Add2ItemCell:getBaseObject())
        end)
        self.box3Add2Text:setText("+" .. tostring(reward3[2].num))
    end
end

return BoxLevelUpUI