local this = class("modulePetMountInfo", G_UIModuleBase)
local petLevelTpl = L_GameTpl:getPetLevelTpl()
local petTpl = L_GameTpl:getPetTpl()
local mountTpl = L_GameTpl:getMountTpl()
local templateValueTpl = L_GameTpl:getTemplateValueTpl()
local mountType = {
  [1] = "ui_modulePetCatalogDetail_01",
  [2] = "ui_modulePetCatalogDetail_02",
  [3] = "ui_modulePetCatalogDetail_03",
  [4] = "ui_modulePetCatalogDetail_04"
}

function this.bind()
  return {
    speed = "???",
    canRide = true,
    list_moveType = {
      moduleName = "pages/pet/new/cellPetMoveType"
    },
    active_self = true,
    show_speed = true
  }
end

function this.methods()
  return {}
end

function this:setGuid(guid)
  local pet = L_PetStore:getPetItem(guid)
  self._guid = guid
  local tpl = petTpl:getTplById(pet.id)
  local isUnlockRide = petTpl:getIsMount(tpl) and L_SystemUnlockStore:getSystemIsOpen(L_SystemConst.enum.mount)
  self.bind.canRide = petTpl:getIsMount(tpl)
  if not petTpl:getIsMount(tpl) then
    self.bind.active_self = false
    return
  end
  self.bind.active_self = true
  self.bind.list_moveType:clear()
  if isUnlockRide then
    self.bind.speed = string.format("%s", L_MountManager:getMountSpeed(self._guid, 1))
  end
  if self.bind.canRide then
    local tpl_mount = mountTpl:getTplById(pet.id)
    local moveType = mountTpl:getMoveType(tpl_mount)
    local tmp = {}
    for i, v in pairs(moveType) do
      table.insert(tmp, {
        moveType = v,
        img_icon = string.format("UI/Atlas/PetSaddlePage/tex_petsaddle_icon_%s.png", v),
        txt_moveType = L_WordsTpl:getValue(mountType[v])
      })
    end
    self.bind.list_moveType:insert_array(tmp)
  end
end

function this:setConfigId(configId)
  local tpl = petTpl:getTplById(configId)
  local isUnlockRide = petTpl:getIsMount(tpl) and L_SystemUnlockStore:getSystemIsOpen(L_SystemConst.enum.mount)
  self.bind.canRide = petTpl:getIsMount(tpl)
  if not petTpl:getIsMount(tpl) then
    self.bind.active_self = false
    return
  end
  self.bind.active_self = true
  self.bind.list_moveType:clear()
  if isUnlockRide then
    self.bind.show_speed = false
  end
  if self.bind.canRide then
    local tpl_mount = mountTpl:getTplById(configId)
    local moveType = mountTpl:getMoveType(tpl_mount)
    local tmp = {}
    for i, v in pairs(moveType) do
      table.insert(tmp, {
        moveType = v,
        img_icon = string.format("UI/Atlas/PetSaddlePage/tex_petsaddle_icon_%s.png", v),
        txt_moveType = L_WordsTpl:getValue(mountType[v])
      })
    end
    self.bind.list_moveType:insert_array(tmp)
  end
end

return this
