local SignMonthCell = class("sign_month_cell", BaseCell)

function SignMonthCell:init()
	local uiMap = self:getUIMap()	
	self.txDay = uiMap["sign_month_cell.tx_day"]
	self.bg = uiMap["sign_month_cell.bg"]
	self.imgAd = uiMap["sign_month_cell.btn_ad.check"]
	if DataManager.PaymentData:getIsSkipAd() then
		self.imgAd:setSprite(GConst.ATLAS_PATH.COMMON,  "common_ad_2")
	else
		self.imgAd:setSprite(GConst.ATLAS_PATH.COMMON,  "common_ad_1")
	end
	self.rewardCell = uiMap["sign_month_cell.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
	self.btn_ad = uiMap["sign_month_cell.reward_cell.btn_ad"]
	self.btn_ad:addClickListener(function()
		local signState = DataManager.SignMonthData:getSignState(self.day)
		if signState == GConst.SignConst.SIGN_STATE.CAN_SIGN_AD then
			self:OnClickSignAgain()
		end
	end)
	self:addClickListener(function()
		local signState = DataManager.SignMonthData:getSignState(self.day)
		if signState == GConst.SignConst.SIGN_STATE.CAN_SIGN then
			self:OnClickSign()
		end
	end)
end

function SignMonthCell:OnClickSignAgain()
	SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.AD_SIGN_MONTH_AGAIN, function ()
    	ModuleManager.SignManager:reqMonthSignAgain()
	end)
end

function SignMonthCell:OnClickSign()
    ModuleManager.SignManager:reqMonthSign(self.day)
end

function SignMonthCell:refresh(day)
	self.day = day
	local showCheck = false
	local showFrame = false
	local reward = DataManager.SignMonthData:getReward(GConst.SignConst.MONTH_REWARD_TYPE.SIGN, day)
	local signState = DataManager.SignMonthData:getSignState(day)
	self.rewardCell:refreshByConfig(reward, showCheck, showCheck)

	self.txDay:setText(I18N:getGlobalText(I18N.GlobalConst.FIRST_CHARGE_1,day))
	if signState == GConst.SignConst.SIGN_STATE.CAN_SIGN then
		--可以领取状态
		self.btn_ad:setActive(false)
		self.rewardCell:addClickListener(function()
			local signState = DataManager.SignMonthData:getSignState(self.day)
			if signState == GConst.SignConst.SIGN_STATE.CAN_SIGN then
				self:OnClickSign()
			end
		end)
		showFrame = true
		self.bg:setSprite(GConst.ATLAS_PATH.UI_ACT_MONTH_SIGNIN, "act_month_signin_bg_4")	
	elseif signState == GConst.SignConst.SIGN_STATE.CAN_SIGN_AD then
		--可以领取广告
		self.btn_ad:setActive(true)
		self.bg:setSprite(GConst.ATLAS_PATH.UI_ACT_MONTH_SIGNIN, "act_month_signin_bg_4")	
		self.rewardCell:addClickListener(function()
			local signState = DataManager.SignMonthData:getSignState(self.day)
			if signState == GConst.SignConst.SIGN_STATE.CAN_SIGN_AD then
				self:OnClickSignAgain()
			end
	end)
	elseif signState == GConst.SignConst.SIGN_STATE.UNABLE_SIGN then
		--不可领取
		self.btn_ad:setActive(false)
		self.bg:setSprite(GConst.ATLAS_PATH.UI_ACT_MONTH_SIGNIN, "act_month_signin_bg_3")	
		self.rewardCell:setClickShowTips(true)
	elseif signState == GConst.SignConst.SIGN_STATE.SIGNEDIN then
		--已签到
		showCheck = true
		self.btn_ad:setActive(false)
		self.bg:setSprite(GConst.ATLAS_PATH.UI_ACT_MONTH_SIGNIN, "act_month_signin_bg_5")	
		self.rewardCell:setClickShowTips(true)
	end
	if showFrame then
		self.rewardCell:showFrameAnimation()
	else
		self.rewardCell:hideFrameAnimation()
	end
	self.rewardCell:showMask(showCheck, showCheck)
end

return SignMonthCell