local Component = require (GConst.TYPEOF_LUA_CLASS.LUA_COMPONENT)
local PopSkipBar = class("PopSkipBar", Component)

function PopSkipBar:init()
	self.currVisible = true
	local uiMap = self.baseObject:genAllChildren()

	self.onIcon = uiMap["pop_skip_bar.bg.toggle_bg.ok"]
	self.text = uiMap["pop_skip_bar.bg.toggle_bg.Label"]
	self.toggle_Btn = uiMap["pop_skip_bar.bg.toggle_bg"]

	self.Bg = uiMap["pop_skip_bar.bg"]

	self.Bg:setAnchoredPositionY(-110)
	self:setVisible(false)
	self.text:setText(I18N:getGlobalText(I18N.GlobalConst.CONFIRM_IGNORE))
	self:_addClickListener(self.toggle_Btn,function ()
		local flag = DataManager.ActivityData:getLoginPopSkipFlag()
		DataManager.ActivityData:setLoginPopSkipFlag(not flag)
		self:refreshIcon()
	end)
end

function PopSkipBar:show()
	self:setVisible(true)
	self:refreshIcon()
end

function PopSkipBar:setVisible(visible)
	if self.currVisible == visible then
		return
	end
	self.currVisible = visible
	if visible then
		self.baseObject:setVisible(true)
	else
		self.baseObject:setVisible(false)
	end
end

function PopSkipBar:_addClickListener(Btn, callback)
    if callback then
        Btn:addClickListener(callback)
    end
end

function PopSkipBar:refreshIcon()
	local flag = DataManager.ActivityData:getLoginPopSkipFlag()
	self.onIcon:setActive(flag)
end

return PopSkipBar