local this = class("moduleAnnounceScrollView", G_UIModuleBase)

function this.bind()
  return {
    scrollList_type = {
      moduleName = "pages/announcement/cellAnnouncementTitle"
    },
    pos_select = C_Vector2(230.6, -60)
  }
end

function this.methods()
  return {
    scrollList_type = {
      onClick_select = function(self, selectTitleId)
        if self.selectTitleId == selectTitleId then
          return
        end
        if self.checkTypeFunc then
          self.checkTypeFunc(selectTitleId)
        end
        self.selectTitleId = selectTitleId
        self:setTitleListActive()
      end
    }
  }
end

function this:initModule(titleList, selectTitleId, checkTypeFunc)
  self.checkTypeFunc = checkTypeFunc
  self:initTitleList(titleList)
  if self.selectTitleId ~= selectTitleId then
    self.selectTitleId = selectTitleId
    if self.checkTypeFunc then
      self.checkTypeFunc(selectTitleId)
    end
  end
  self:setTitleListActive()
  self.bind.pos_select = C_Vector2(230.6, -60)
end

function this:getSelectTitleId()
  return self.selectTitleId
end

function this:initTitleList(titleList)
  local tmp = {}
  for i = 1, #titleList do
    if i > self.bind.scrollList_type:getLength() then
      self.bind.scrollList_type:insert(titleList[i])
    else
      self.bind.scrollList_type:change(i, titleList[i])
    end
  end
  for i = self.bind.scrollList_type:getLength(), #titleList + 1, -1 do
    self.bind.scrollList_type:remove(i)
  end
end

function this:setTitleListActive()
  for i = 1, #self.bind.scrollList_type do
    local active = false
    if self.bind.scrollList_type:getValue(i, "id") == self.selectTitleId then
      active = true
    end
    self.bind.scrollList_type:change(i, {
      go_active = active,
      go_normal = not active
    })
  end
end

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

return this
