local this = class("cellAnnouncementTitle", G_UIModuleBase)

function this.bind()
  return {
    go_active = false,
    go_normal = false,
    title = "",
    title2 = ""
  }
end

function this.methods()
  return {
    onClick_select = function(self)
      if self.bind.id == self.parent.selectTitleId then
        self.isSampleType = true
        return
      else
        self.isSampleType = false
      end
      self:emit("onClick_select", self.bind.id)
      if not self.isSampleType then
        self.parent.bindComponents.mainContentAnim:Stop()
        self.parent.bindComponents.mainContentAnim:Play()
        L_AudioUtil.playSound("Play_SFX_System_UI_Post_Menu_Tab_Click")
        self:doSelectTween()
      end
    end
  }
end

function this:open()
end

function this:refresh()
  if self.cacheId == self.bind.id then
    return
  end
  self.cacheId = self.bind.id
  if self:checkShowRedDot() then
    L_ReddotManager:registerReddot(self.bindComponents.reddotNew, string.format(L_ReddotManager.DotDef.AnnouncementActive, self.bind.id))
  else
    self.bindComponents.reddotNew.gameObject:SetActive(false)
  end
  self:initTitle()
end

function this:checkShowRedDot()
  return self.parent:checkShowRedDot()
end

function this:initTitle()
  local data = L_AnnouncementStore:getAnnouncementDataById(self.bind.id)
  local title = ""
  if data ~= nil then
    title = data:getTitle()
  end
  self.bind.title = title
  self.bind.title2 = title
end

function this:doSelectTween()
  local pos_select = self.parent.bind.pos_select
  local pos_target = self.bindComponents.pos_go.anchoredPosition
  local _curve_announce = self.parent.bindComponents.pageAnnounceTweenCurve.curves[0]
  local getter = function()
    return pos_select.y
  end
  local setter = function(v)
    self.parent.bind.pos_select = L_Vector3.new(230.6, v)
  end
  if self.selectTween then
    self.selectTween:Kill()
  end
  self.selectTween = DOTween.To(getter, setter, pos_target.y, 0.443):SetEase(_curve_announce)
  self.selectTween:SetAutoKill(true)
  self.selectTween:Play()
end

return this
