local this = class("moduleKiboList", G_UIModuleBase)

function this.bind()
  return {
    playerList = {
      moduleName = "pages/petDuel/cellKiBoOnDuel"
    },
    enemyList = {
      moduleName = "pages/petDuel/cellKiBoOnDuel"
    }
  }
end

function this.methods()
  return {}
end

function this:open()
  L_KiBoDuelManager:addListener(L_KiBoDuelManager.event.refreshKiboList, self.onRefreshKiboList, self)
  L_KiBoDuelManager:addListener(L_KiBoDuelManager.event.restartKiBoDuel, self.restartKiBoDuel, self)
end

function this:close()
  L_KiBoDuelManager:removeListener(L_KiBoDuelManager.event.refreshKiboList, self.onRefreshKiboList, self)
  L_KiBoDuelManager:removeListener(L_KiBoDuelManager.event.restartKiBoDuel, self.restartKiBoDuel, self)
end

function this:restartKiBoDuel()
  self.bind.playerList:clear()
  self.bind.enemyList:clear()
end

function this:onRefreshKiboList(data)
  local playerData, enemyData = L_KiBoDuelManager:getKiBoList()
  for i, v in pairs(playerData) do
    v.isPlayerPet = true
  end
  if data.isPlayer then
    self.bind.playerList:clear()
    self.bind.playerList:insert_array(playerData)
  else
    self.bind.enemyList:clear()
    self.bind.enemyList:insert_array(enemyData)
  end
end

return this
