local module = class("cellHomeCenterPetStationedManageBox", require("ui.pages.pet.cellPetBox"))

function module:refreshSinglePet(pet)
  local petGuid = pet.guid
  if self.petGuidDic[petGuid] == true then
    self:refreshInfo()
  end
end

function module:refreshBoxList(guid)
end

function module:refreshInfo()
  if not self.isBind then
    return
  end
  local onClick_pet = function(cell)
    self:emit("onClick_pet", cell.bind.guid)
  end
  local boxIndex = self.bind.boxIndex
  local countList = L_PetStore:getPetBoxList(boxIndex)
  local data = {}
  self.petGuidDic = self.petGuidDic or {}
  if not table.isEmpty(countList) then
    for _, v in ipairs(countList) do
      local pet = L_PetStore:getPetItem(v)
      if not table.isEmpty(pet) then
        local petGuid = pet.guid
        self.petGuidDic[petGuid] = true
        local csPetData = L_PetStore:getCsPetData(petGuid)
        local inInHomeHub = csPetData:GetIsInHomeHub()
        if not inInHomeHub then
          table.insert(data, pet)
        else
          table.insert(data, {})
        end
      else
        table.insert(data, {})
      end
    end
  end
  local lst = {}
  for i = 1, #data do
    local cell = {}
    if not table.isEmpty(data[i]) then
      cell.filterType = self.parent:getFilterType()
      cell.guid = countList[i]
      cell.itemType = L_Const.resType.pet
      cell.reddotName = string.format(L_ReddotManager.DotDef.PetNew, countList[i])
      cell.reddotGeneName = string.format(L_ReddotManager.DotDef.PetGeneMutation, countList[i])
      cell.callback = onClick_pet
    end
    table.insert(lst, cell)
  end
  self.bind.list_pet:clear()
  self.bind.list_pet:insert_array(lst)
end

return module
