local this = class("pageCommonIntroduction", G_UIPageBase)
local introductionTpl = L_GameTpl:getIntroductionTpl()

function this.bind()
  return {
    title = "",
    pic = "",
    desc = "",
    switchNodeAcitve = false,
    currentPage = "",
    totalPages = "",
    nextMaskActive = false,
    previousMaskActive = false,
    nextBtnActive = false,
    previousBtnActive = false,
    picActive = true
  }
end

function this.methods()
  return {
    onClick_nextBtn = function(self)
      if self.currentIndex < self.maxPageNum then
        self.currentIndex = self.currentIndex + 1
      end
      self:refreshPage()
    end,
    onClick_previousBtn = function(self)
      if self.currentIndex > 1 then
        self.currentIndex = self.currentIndex - 1
      end
      self:refreshPage()
    end,
    onClick_closeBtn = function(self)
      L_UI:close(self.pageName)
    end,
    onClick_mask = function(self)
      L_UI:close(self.pageName)
    end
  }
end

function this:preOpen(options)
  self.groupId = options.groupId
  self:initPages()
end

function this:initPages()
  if math.isEmpty(self.groupId) then
    return
  end
  self.pages = introductionTpl:getPages(self.groupId)
  self.currentIndex = 1
  self.maxPageNum = #self.pages
  self.bind.totalPages = tostring(self.maxPageNum)
  self.bind.switchNodeAcitve = 1 < self.maxPageNum
  self:refreshPage()
end

function this:refreshPage()
  local tpl = self.pages[self.currentIndex]
  self.bind.nextBtnActive = self.currentIndex < self.maxPageNum
  self.bind.previousBtnActive = self.currentIndex > 1
  self.bind.nextMaskActive = not self.bind.nextBtnActive
  self.bind.previousMaskActive = not self.bind.previousBtnActive
  self.bind.currentPage = tostring(self.currentIndex)
  self.bind.desc = introductionTpl:getContent(tpl)
  self.bind.pic = introductionTpl:getPicture(tpl)
  self.bind.title = introductionTpl:getTitle(tpl)
  self.bind.picActive = introductionTpl:getIsPictureIntroduction(tpl)
end

function this:escHandle()
  L_UI:close(self.pageName)
end

return this
