local ActivityUI = class("ActivityUI", BaseUI)
local SPINE_BANNER = {
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1] = "ui_act_summer_buy_2",
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2] = "ui_act_summer_buy_1",
}
local PANEL_BG = {
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1] = "assets/arts/textures/background/shop/shop_bg_11.png",
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2] = "assets/arts/textures/background/shop/shop_bg_pig.png",
}
local TITLE_BG = {
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1] = "common_title_10",
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2] = "common_title_12",
}
local OFF_BG = {
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1] = "shop_bg_18",
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2] = "shop_bg_9",
}
local LINE_BG = {
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1] = "act_summer_board_6",
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2] = "act_summer_board_5",
}
local SPINE_POS_Y = {
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1] = 340,
    [GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2] = 285,
}

function ActivityUI:isFullScreen()
    return false
end

function ActivityUI:getPrefabPath()
    return "assets/prefabs/ui/activity/activity_bounty_buy_ui.prefab"
end

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

function ActivityUI:ctor(parmas)
    self.payType = parmas
    if self.payType == GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY1 then
        self.giftId = GConst.ActivityConst.BOUNTY_GIFT_ID_1
    elseif self.payType == GConst.ActivityConst.BOUNTY_GRADE_TYPE.PAY2 then
        self.giftId = GConst.ActivityConst.BOUNTY_GIFT_ID_2
    end
end

function ActivityUI:onLoadRootComplete()
    local uiMap = self.root:genAllChildren()
    self.bg = uiMap["activity_bounty_buy_ui.bg"]
    self.spineBanner = uiMap["activity_bounty_buy_ui.bg.spine_banner"]
    self.imgTitle = uiMap["activity_bounty_buy_ui.bg.img_title"]
    self.txTitle = uiMap["activity_bounty_buy_ui.bg.img_title.tx_title"]
    self.imgOff = uiMap["activity_bounty_buy_ui.bg.img_off"]
    self.txOff = uiMap["activity_bounty_buy_ui.bg.img_off.tx_off"]
    self.txDesc = uiMap["activity_bounty_buy_ui.bg.tx_desc"]
    self.line = uiMap["activity_bounty_buy_ui.bg.line"]
    self.scrollrectComp = uiMap["activity_bounty_buy_ui.bg.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
    self.btnBuy = uiMap["activity_bounty_buy_ui.bg.btn_buy"]
    self.txBuy = uiMap["activity_bounty_buy_ui.bg.btn_buy.tx_buy"]
    self.btnClose = uiMap["activity_bounty_buy_ui.bg.close_btn"]

    self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.REWARD_PREVIEW_DESC))
    self.txDesc:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_DESC_11))

    self.btnBuy:addClickListener(function()
        ModuleManager.ActivityManager:buySummerBounty(self.giftId)
    end)
    self.btnClose:addClickListener(function()
        self:closeUI()
    end)
    self:addEventListener(EventManager.CUSTOM_EVENT.ACTIVITY_SUMMER_END, function()
        self:closeUI()
    end)
    self:bind(DataManager.ShopData, "isDirty", function()
		self:closeUI()
	end)
end

function ActivityUI:onRefresh()
    self.spineBanner:getSkeletonGraphic().enabled = false
    self.spineBanner:loadAssetAsync(SPINE_BANNER[self.payType], function()
        self.spineBanner:getSkeletonGraphic().enabled = true
        self.spineBanner:playAnim("idle", true, true, true)
    end, false)
    self.spineBanner:setAnchoredPositionY(SPINE_POS_Y[self.payType])

    self.bg:setTexture(PANEL_BG[self.payType])
    self.imgTitle:setSprite(GConst.ATLAS_PATH.COMMON, TITLE_BG[self.payType])
    self.imgOff:setSprite(GConst.ATLAS_PATH.SHOP, OFF_BG[self.payType])
    self.line:setSprite(GConst.ATLAS_PATH.ACT_SUMMER, LINE_BG[self.payType])
    local gift = DataManager.ShopData:getActGiftConfig()[self.giftId]
    if gift.value then
        self.imgOff:setActive(true)
        self.txOff:setText(gift.value .. "%")
    else
        self.imgOff:setActive(false)
    end
    self.txBuy:setText(GFunc.getFormatPrice(gift.recharge_id))

    local totalRewards = DataManager.ActivityData:getBountyGradeAllRewardSort(self.payType)
	self.scrollrectComp:addInitCallback(function()
		return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
	end)
	self.scrollrectComp:addRefreshCallback(function(index, cell)
		cell:refreshByConfig(totalRewards[index])
	end)
	self.scrollrectComp:clearCells()
	self.scrollrectComp:refillCells(#totalRewards)
end

return ActivityUI