local FreeDailyRewardsComp = class("FreeDailyRewardsComp", LuaComponent)

function FreeDailyRewardsComp:init()
	local uiMap = self:getUIMap()
	self.titleTx = uiMap["free_daily_rewards.title_tx"]
	self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.PRIVILEGE_CARD_NAME_1))

	self.rewadCell = uiMap["free_daily_rewards.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)

	self.getBtn = uiMap["free_daily_rewards.btn_get"]
	self.getBtn:addClickListener(function()
		ModuleManager.PrivilegeCardManager:getFreeDailyRewards()
	end)
	self.getBtnTx = uiMap["free_daily_rewards.btn_get.text"]
	self.getBtnGrey = uiMap["free_daily_rewards.btn_grey"]
	self.getBtnGreyTx = uiMap["free_daily_rewards.btn_grey.text"]
end

function FreeDailyRewardsComp:refresh()
	self.getBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM))
	self.getBtnGreyTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_DONE))

	local isClaimed = DataManager.PrivilegeCardData:getIsClaimedFreeDailyReward()
	local reward = GFunc.getConstCost("card_free_dailyreward")
	if reward then
		self.rewadCell:refreshByConfig(reward, isClaimed, isClaimed)
		if isClaimed then
			self.rewadCell:hideFrameAnimation()
            self.rewadCell:setClickShowTips()
		else
			self.rewadCell:showFrameAnimation()
			self.rewadCell:addClickListener(function()
				ModuleManager.PrivilegeCardManager:getFreeDailyRewards()
			end)
		end
	end

	self.getBtn:setActive(not isClaimed)
	if not isClaimed then
		self.getBtn:addRedPoint(70, 30, 1)
	else
		self.getBtn:removeRedPoint()
	end
	self.getBtnGrey:setActive(isClaimed)
end

return FreeDailyRewardsComp