local AdCardComp = class("AdCardComp", LuaComponent)

function AdCardComp:init()
	local uiMap = self:getUIMap()
	self.titleTx = uiMap["ad_card.title_tx"]
	self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.PRIVILEGE_CARD_NAME_2))
	self.descTx = uiMap["ad_card.desc_tx"]
	self.descTx:setText(I18N:getGlobalText(I18N.GlobalConst.PRIVILEGE_CARD_DESC_2))
	self.descTx2 = uiMap["ad_card.desc_tx_2"]

	self.rewardDescTx = uiMap["ad_card.reward_bg.text"]
	self.rewardDescTx:setText(I18N:getGlobalText(I18N.GlobalConst.PRIVILEGE_CARD_DESC_3))
	self.rewadCell = uiMap["ad_card.reward_bg.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)

	self.offImg = uiMap["ad_card.off_img"]
	self.offText1 = uiMap["ad_card.off_img.text"]
	self.offText2 = uiMap["ad_card.off_img.text_2"]
	self.offText2:setText(I18N:getGlobalText(I18N.GlobalConst.VALUE_DESC))

	uiMap["ad_card.ui_spine_obj"]:playAnim("idle", true, true)

	self.payBtn = uiMap["ad_card.pay_btn"]
	self.payBtn:addClickListener(function()
		ModuleManager.PrivilegeCardManager:buyAdCard()
	end)
	self.payBtnTx = uiMap["ad_card.pay_btn.text"]
end

function AdCardComp:refresh()
	local cfg = DataManager.ShopData:getActGiftConfig(GConst.ShopConst.PRIVILEGE_CARD_ID.CARD_AD)
	if cfg == nil then
		return
	end
	local isActive = DataManager.PrivilegeCardData:getIsCardActive(GConst.ShopConst.PRIVILEGE_CARD_ID.CARD_AD)
	if isActive then
		self.descTx2:setText("<color=#4BFF53>" .. I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_12) .. "</color>")
		self.payBtn:setActive(false)
    else
		self.descTx2:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_13))
		self.payBtn:setActive(true)
        self.payBtnTx:setText(GFunc.getFormatPrice(cfg.recharge_id))
    end
	local rewards = cfg.reward
	if rewards and rewards[1] then
		self.rewadCell:refreshByConfig(rewards[1], isActive, isActive)
	end
	if cfg.value then
		self.offImg:setVisible(true)
		self.offText1:setText(cfg.value .. "%")
	else
		self.offImg:setVisible(false)
	end
end

return AdCardComp