local ActBountyCellV1 = class("ActBountyCellV1", BaseCell)

function ActBountyCellV1:init()
	local uiMap = self:getUIMap()
	self.dayIcon = uiMap["bounty_cell.day_icon"]
    self.dayTx = uiMap["bounty_cell.day_icon.day_tx"]
	self.dayTxGrey = uiMap["bounty_cell.day_icon.day_tx_grey"]
    self.upSlider = uiMap["bounty_cell.up_slider"]
    self.upIcon = uiMap["bounty_cell.up_slider.icon"]
    self.downSlider = uiMap["bounty_cell.down_slider"]
    self.downIcon = uiMap["bounty_cell.down_slider.icon"]
	self.bg = uiMap["bounty_cell.bg"]
    self.freeRewardCell = uiMap["bounty_cell.reward_free.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
    self.proRewardCells = {}
	for i = 1, 2 do
		self.proRewardCells[i] = uiMap["bounty_cell.reward_pro.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
	end
end
function ActBountyCellV1:refresh(day, maxDay, info)
    local curDay = DataManager.ActSprintSummonDataAll:getBountyCurrDay()
	local freeGot = DataManager.ActSprintSummonDataAll:getHasGotBountyReward(0, day)
	local proGot = DataManager.ActSprintSummonDataAll:getHasGotBountyReward(1, day)
	local freeCanGet = DataManager.ActSprintSummonDataAll:canClaimBountyReward(0, day)
	local proCanGet = DataManager.ActSprintSummonDataAll:canClaimBountyReward(1, day)
	local rewardFree = info.reward[1]
	local rewardPro1 = info.reward_pro[1]
    local rewardPro2 = info.reward_pro[2]
	local isUnlockPro = DataManager.ActSprintSummonDataAll:isUnlockBountyPro()

	local dayStr = tostring(day)
	self.dayTx:setText(dayStr)
	self.dayTxGrey:setText(dayStr)

	-- 刷新slider部分
	self.upSlider:setVisible(day ~= 1)
	self.downSlider:setVisible(day ~= maxDay)
	self.upIcon:setVisible(day <= curDay)
	self.downIcon:setVisible(day < curDay)

	-- 奖励
	self.freeRewardCell:refreshByConfig(rewardFree, freeGot, freeGot)
    if freeCanGet then
        self.freeRewardCell:showFrameAnimation()
        self.freeRewardCell:addClickListener(function()
			self:onClickClaimRewards()
		end)
		self.dayTx:setVisible(true)
		self.dayTxGrey:setVisible(false)
		GFunc.setGrey(self.bg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE), false)
		GFunc.setGrey(self.dayIcon:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE), false)
    else
        self.freeRewardCell:hideFrameAnimation()
		self.freeRewardCell:setClickShowTips()
		self.dayTx:setVisible(freeGot)
		self.dayTxGrey:setVisible(not freeGot)
		GFunc.setGrey(self.bg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE), not freeGot)
		GFunc.setGrey(self.dayIcon:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE), not freeGot)
    end
	self.proRewardCells[1]:refreshByConfig(rewardPro1, proGot, proGot)
	if rewardPro2 then
		self.proRewardCells[2]:setActive(true)
		self.proRewardCells[2]:refreshByConfig(rewardPro2, proGot, proGot)
	else
		self.proRewardCells[2]:setActive(false)
	end
	self.proRewardCells[1]:showLock(not isUnlockPro)
	self.proRewardCells[2]:showLock(not isUnlockPro)

	if proCanGet and isUnlockPro and not proGot then
		self.proRewardCells[1]:showFrameAnimation()
		self.proRewardCells[2]:showFrameAnimation()
		self.proRewardCells[1]:addClickListener(function()
			self:onClickClaimRewards()
		end)
		self.proRewardCells[2]:addClickListener(function()
			self:onClickClaimRewards()
		end)
	else
		self.proRewardCells[1]:hideFrameAnimation()
		self.proRewardCells[2]:hideFrameAnimation()
		self.proRewardCells[1]:setClickShowTips()
		self.proRewardCells[2]:setClickShowTips()
	end
end

function ActBountyCellV1:onClickClaimRewards()
	local actId = DataManager.ActSprintSummonDataAll:getActId()
	local actType = DataManager.ActivityData:getActType(actId)
	local grade = DataManager.ActSprintSummonDataAll:isUnlockBountyPro() and 1 or 0
	ModuleManager.ActSprintManager:reqSprintBountySign(actType, actId, grade)
end

return ActBountyCellV1