local ActBountyCompV1 = class("ActBountyCompV1", LuaComponent)

local CELL = "app/ui/activity/common/cell/act_bounty_cell_v1"

function ActBountyCompV1:init()
	local uiMap = self:getUIMap()
	-- self.txTitle = uiMap["act_bounty_comp_v1.top.title_tx"]
	-- self.txTime = uiMap["act_bounty_comp_v1.top.time_bg.time_tx"]
	-- self.banner = uiMap["act_bounty_comp_v1.top.banner"]
	self.scrollrectPrefab = uiMap["act_bounty_comp_v1.scrollrect"]
	self.scrollrect = self.scrollrectPrefab:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)

	self.getBtn = uiMap["act_bounty_comp_v1.get_btn"]
	self.getBtn:addClickListener(function()
		local actId = self.data:getActId()
		local actType = self.data:getActType(actId)
		local grade = self.data:isUnlockBountyPro() and 1 or 0
		ModuleManager.ActSprintManager:reqSprintBountySign(actType, actId, grade)
	end)
	self.getBtnTx = uiMap["act_bounty_comp_v1.get_btn.text"]
	self.getBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.ONE_KEY_GET_DESC))
	self.payBtn = uiMap["act_bounty_comp_v1.pay_btn"]
	self.payBtn:addClickListener(function()
		if self.data:isUnlockBountyPro() then
			return
		end
		local giftId = self.data:getBountyProGiftId()
		ModuleManager.ActSprintManager:onBuyBountyPro(giftId)
	end)
	self.payBtnTx = uiMap["act_bounty_comp_v1.pay_btn.text"]

	uiMap["act_bounty_comp_v1.scrollrect.title.level_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_HERO_SUIT_DESC_4))
	uiMap["act_bounty_comp_v1.scrollrect.title.desc_tx_1"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_HERO_SUIT_DESC_5))
	uiMap["act_bounty_comp_v1.scrollrect.title.desc_tx_2"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_HERO_SUIT_DESC_6))

	self.scrollrect:addInitCallback(function()
		return CELL
	end)
	self.scrollrect:addRefreshCallback(function(index, cell)
		cell:refresh(index, #self.cfgList, self.cfgList[index])
	end)
	self.scrollrect:clearCells()
end

-- function ActBountyCompV1:updateTime()
-- 	self.txTime:setText(Time:formatNumTimeStr(self.data:getRemainTime()))
-- end

function ActBountyCompV1:setParentUI(parentUI, dataKey)
	self.parentUI = parentUI
	self.dataKey = dataKey
	self.data = DataManager[dataKey]
end

function ActBountyCompV1:refresh()
	local actId = self.data:getActId()
	-- self.txTitle:setText(I18N:getGlobalText(GConst.ActSprintConst.ACT_LIST_NAME[actId]))
	-- self.banner:setTexture(GConst.ActSprintConst.ACT_MAIN_BANNER[actId])
	self.getBtn:setActive(self.data:isHaveUnclaimedBountyReward())
	self.payBtn:setActive(not self.data:isUnlockBountyPro())
	local rechargeId = self.data:getBountyProRechargeId()
	self.payBtnTx:setText(GFunc.getFormatPrice(rechargeId))
	self:refreshScrollRect()
end

function ActBountyCompV1:refreshScrollRect()
	self.cfgList = self.data:getBountyCfgList()
	self.scrollrect:refillCells(#self.cfgList)
end

return ActBountyCompV1