local this = class("pageGuideInfoWindow", G_UIPageBase)

function this.bind()
  return {
    desPic = "",
    toggle_enableNextBtn = false,
    toggle_enablePreviousBtn = false,
    currentNum = 1,
    totalNum = 9,
    descText = "",
    titleText = "",
    active_closeTip = true,
    active_closeBtn = false,
    sortingOrder_page = 9450,
    txt_closeTip = "",
    active_showTurnBtn = true
  }
end

function this.methods()
  return {
    onChangePic = function(self, name)
      if name == "changePic" then
        self.bind.currentNum = self.bind.currentNum + 1
      elseif name == "changePicPrevious" then
        self.bind.currentNum = self.bind.currentNum - 1
      end
      self:updateUI()
      self.onSwitchPic = false
    end,
    onClick_nextBtn = function(self)
      if self.onSwitchPic then
        return
      end
      self.bindComponents.guideInfoAnimation:Stop()
      if self.bind.currentNum < self.maxPicNum then
        self.onSwitchPic = true
        self.bindComponents.guideInfoAnimation:Play("anim_guide_guidepage_switch")
      end
    end,
    onClick_previousBtn = function(self)
      if self.onSwitchPic then
        return
      end
      self.bindComponents.guideInfoAnimation:Stop()
      if self.bind.currentNum > 1 then
        self.onSwitchPic = true
        self.bindComponents.guideInfoAnimation:Play("anim_guide_guidepage_switch_toPrevious")
      end
    end,
    onClick_closeBtn = function(self)
      if self.finishCallback then
        self.finishCallback()
      end
      L_UI:close(self.pageName)
    end,
    onClick_closeBtn2 = function(self)
      if self.finishCallback then
        self.finishCallback()
      end
      L_UI:close(self.pageName)
    end
  }
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  self.pics = options.pics
  self.maxPicNum = #self.pics
  self.bind.active_showTurnBtn = self.maxPicNum > 1
  self.bind.currentNum = 1
  self.bind.totalNum = self.maxPicNum
  self.finishCallback = options.finishCallback
  self.bind.txt_closeTip = L_GameTpl:getWordsTpl():getValue("notice_guide_img_tip")
  self.bind.active_closeTip = true
  self.bind.active_closeBtn = false
  self.isPicNumMax = false
  self.bind.sortingOrder_page = 9450
  self:updateUI()
  self.ability = C_TagStateManager.CreateState(C_TagStateDefine.GuideTip)
  self.ability:TryActive()
end

function this:updateUI()
  self.bind.toggle_enableNextBtn = self.bind.currentNum < self.maxPicNum
  self.bind.toggle_enablePreviousBtn = self.bind.currentNum > 1
  if not self.isPicNumMax and self.bind.currentNum >= self.maxPicNum then
    self.bind.active_closeTip = false
    self.bind.active_closeBtn = true
    self.isPicNumMax = true
  end
  local guideTpl = L_GameTpl:getGuidePicTpl()
  local tpl = guideTpl:getTplById(tonumber(self.pics[self.bind.currentNum]))
  local icon = guideTpl:getIcon(tpl)
  self.bind.desPic = icon
  self.bind.titleText = guideTpl:getTitle(tpl)
  self.bind.descText = guideTpl:getDesc(tpl)
end

function this:escHandle()
end

function this:close()
  C_TagStateManager.ReleaseState(self.ability)
end

return this
