local UIDailyPackBtn = BaseClass("UIDailyPackBtn", UIBaseContainer)
local base = UIBaseContainer
local RefrehsRedPoint = function(self, list)
  local rechargeList = list
  if rechargeList == nil then
    rechargeList = WelfareController.getShowTagInfosWithType(RechargeEntryType.DailySale)
  end
  local redNum = 0
  for k, v in pairs(rechargeList) do
    redNum = redNum + v:getRedDotNum()
  end
  self.redPoint:SetActive(0 < redNum)
end
local RefreshShowState = function(self)
  local show = DataCenter.LWFunctionUnlockManager:CheckCanShow(LWFunctionUnlockType.MainUI_GiftPack)
  if show then
    local list = WelfareController.getShowTagInfosWithType(RechargeEntryType.DailySale)
    if list and 0 < #list then
      show = true
    else
      show = false
    end
  end
  if show then
    self:SetActive(true)
    local showNewTag = self:RefreshNewTag()
    if not showNewTag then
      RefrehsRedPoint(self)
    else
      self.redPoint:SetActive(false)
    end
  else
    self:SetActive(false)
  end
end
local OnBtnClick = function(self)
  GoToUtil.GotoOpenView(UIWindowNames.LWBuyDiamond, {
    anim = false,
    UIMainAnim = UIMainAnimType.AllHide
  }, nil, nil, RechargeEntryType.DailySale)
end
local OnCreate = function(self)
  base.OnCreate(self)
  self:ComponentDefine()
  self:DataDefine()
end
local OnDestroy = function(self)
  self:ComponentDestroy()
  self:DataDestroy()
  base.OnDestroy(self)
end
local OnEnable = function(self)
  base.OnEnable(self)
  self:RefreshNewTag()
end
local OnDisable = function(self)
  base.OnDisable(self)
end
local ComponentDefine = function(self)
  self.nameText = self:AddComponent(UIText, "NameText")
  self.btn = self:AddComponent(UIButton, "")
  self.btn:SetOnClick(function()
    OnBtnClick(self)
  end)
  self.nameText:SetLocalText(2000088)
  self.redPoint = self:AddComponent(UIBaseContainer, "RedPoint")
  self.newTag = self:AddComponent(UIBaseContainer, "DailyPackNew")
  self.newTagText = self:AddComponent(UIText, "DailyPackNew/Bg/Text")
  self.newTagText:SetText("NEW")
end
local ComponentDestroy = function(self)
  self.nameText = nil
  self.btn = nil
  self.redPoint = nil
  self.newTag = nil
  self.newTagText = nil
end
local DataDefine = function(self)
  self.hasSetName = false
end
local DataDestroy = function(self)
  self.hasSetName = false
end
local RefreshNewTag = function(self)
  if self.activeSelf then
    local showNewTag = WelfareController.EntryShowNewTag(RechargeEntryType.DailySale)
    self.newTag:SetActive(showNewTag)
    return showNewTag
  end
  return false
end
local HideNewTag = function(self)
  self.newTag:SetActive(false)
  WelfareController.SetShowNewTagRecord(RechargeEntryType.DailySale)
  RefrehsRedPoint(self)
end
local OnAddListener = function(self)
  base.OnAddListener(self)
  self:AddUIListener(EventId.EnterDailyPack, self.HideNewTag)
  self:AddUIListener(EventId.RefreshMainUIDailyPackBtnNewTag, self.OnRefreshNewTag)
end
local OnRemoveListener = function(self)
  base.OnRemoveListener(self)
  self:RemoveUIListener(EventId.EnterDailyPack, self.HideNewTag)
  self:RemoveUIListener(EventId.RefreshMainUIDailyPackBtnNewTag, self.OnRefreshNewTag)
end

function UIDailyPackBtn:OnRefreshNewTag()
  local showNewTag = self:RefreshNewTag()
  if not showNewTag then
    RefrehsRedPoint(self)
  else
    self.redPoint:SetActive(false)
  end
end

UIDailyPackBtn.OnCreate = OnCreate
UIDailyPackBtn.OnDestroy = OnDestroy
UIDailyPackBtn.OnEnable = OnEnable
UIDailyPackBtn.OnDisable = OnDisable
UIDailyPackBtn.ComponentDefine = ComponentDefine
UIDailyPackBtn.ComponentDestroy = ComponentDestroy
UIDailyPackBtn.DataDefine = DataDefine
UIDailyPackBtn.DataDestroy = DataDestroy
UIDailyPackBtn.RefreshShowState = RefreshShowState
UIDailyPackBtn.RefreshNewTag = RefreshNewTag
UIDailyPackBtn.HideNewTag = HideNewTag
UIDailyPackBtn.OnAddListener = OnAddListener
UIDailyPackBtn.OnRemoveListener = OnRemoveListener
return UIDailyPackBtn
