local this = class("pagePetPreview", G_UIPageBase)
local wordsTpl = L_GameTpl:getWordsTpl()
local _homeBuildingTpl = L_GameTpl:getHomeBuildingTpl()

function this:ctor(...)
  this.super.ctor(self, ...)
end

function this.bind()
  return {
    toggleInfo = true,
    toggleModuleBar = {
      type = "toggleModule",
      modulePetDetail = {
        assetName = "UI/Pages/Pet/modulePetDetail",
        moduleName = "pages/pet/modulePetDetail"
      },
      moduleRankUpPreviewPet = {
        assetName = "UI/Pages/Pet/moduleRankUpPreviewPet",
        moduleName = "pages/Pet/moduleRankUpPreviewPet"
      }
    },
    toggleModuleName = "",
    modulePetSceneMod = {
      type = "toggleModule",
      modulePetSceneMod = {
        assetName = "UI/Pages/Pet/modulePetSceneMod",
        moduleName = "pages/Pet/modulePetSceneMod"
      }
    },
    modulePetSceneModName = "",
    moduleCommonTop = {
      moduleName = "modulePages/moduleCommonTop"
    }
  }
end

function this.methods()
  return {
    toggleInfoBtn = function(self)
      self:returnToDefaultModule()
    end,
    toggleRankUp = function(self)
      local result = L_SystemUnlockManager:checkAndTip(L_SystemConst.enum.petRankUp)
      if not result then
        return
      end
      self.bind.toggleModuleName = "moduleRankUpPreviewPet"
      self.modules.toggleModuleBar.moduleRankUpPreviewPet:infoRefresh(self.petConfigId)
    end
  }
end

function this:check(options, callback)
  local result = L_SystemUnlockManager:checkAndTip(L_SystemConst.enum.pet)
  callback(result)
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  self.petConfigId = options.configId
  self:initData(self.petConfigId)
  self.bind.modulePetSceneModName = "modulePetSceneMod"
  self:refreshPetMod()
  local data = {
    name = L_WordsTpl:getValue("ui_pagePetPreview"),
    helpBtnBool = false,
    mainBtnBool = true,
    closeCurPage = function()
      if self.closeCurPageFunc then
        self.closeCurPageFunc()
        self.closeCurPageFunc = nil
        self.modules.moduleCommonTop:setPageName(L_WordsTpl:getValue("ui_pagePetPreview"))
        return
      end
      L_UI:close(self.pageName)
    end,
    helpBtn = function()
    end,
    mainBtn = function()
      L_UI:backToRoot()
    end
  }
  self.closeCurPageFunc = nil
  self.modules.moduleCommonTop:initModule(data)
  C_CameraManager.SetBrainBlendStyle(L_Const.blendStyle.cut)
  local brain = C_CameraManager.GetMainCameraBrain()
  brain.m_CustomBlends = nil
end

function this:setCommonTopData(func, name)
  self.closeCurPageFunc = func
  self.modules.moduleCommonTop:setPageName(name)
end

function this:close(options)
  this.super.close(self, options)
  self:disableAllModule()
end

function this:initData(petConfigId)
  if not math.isEmpty(petConfigId) then
    self.petConfigId = petConfigId
    self.bind.toggleModuleName = "modulePetDetail"
    L_PetStore:playPetVoiceSound(self.petConfigId, L_PetConst.PetSystemVoiceType.PropertyDetail)
    self.modules.toggleModuleBar.modulePetDetail:infoRefresh(self.petConfigId)
  end
end

function this:refreshPetMod()
  if self.petConfigId then
    self.modules.modulePetSceneMod.modulePetSceneMod:refreshPetMod(self.petConfigId, false, false)
  else
    self.modules.modulePetSceneMod.modulePetSceneMod:disableMod()
  end
end

function this:disableAllModule()
  self.bind.toggleModuleName = ""
end

function this:returnToDefaultModule()
  local petConfigId = self.petConfigId
  if not math.isEmpty(petConfigId) then
    self.bind.toggleModuleName = "modulePetDetail"
    self.bind.toggleInfo = true
    L_PetStore:playPetVoiceSound(self.configId, L_PetConst.PetSystemVoiceType.PropertyDetail)
    self:initData(petConfigId)
  end
end

function this:closePetAdvance()
  self:returnToDefaultModule()
end

return this
