local cls = class("cellPetEggItem", G_UIModuleBase)

function cls.bind()
  return {
    txtPetEggName = "",
    imageIcon = "",
    activeHatching = false,
    activeInQueue = false,
    activeSelect = false,
    activeHatched = false,
    active_content = false
  }
end

function cls.methods()
  return {
    onClick = function(self)
      if math.isEmpty(self.guid) then
        return
      end
      self:emit("onClick_selectId", self.guid)
    end
  }
end

function cls:setSelect(state)
  self.bind.activeSelect = state
end

function cls:refreshView(guid, buildGuid)
  self.guid = guid
  self.buildGuid = buildGuid
  self:setPetEggDataContent(guid, buildGuid)
end

function cls:setPetEggDataContent(guid, buildGuid)
  if math.isEmpty(guid) then
    self.bind.active_content = false
    return
  end
  self.bind.active_content = true
  local petEggData = L_PetStore:getPetEggItem(guid)
  if not petEggData then
    errorf("\229\174\160\231\137\169\232\155\139\230\149\176\230\141\174\228\184\141\229\173\152\229\156\168 uid = " .. tostring(guid))
    return
  end
  local petEggConf = L_ItemTplManager:getPetEggItem(petEggData.configId, guid)
  self.bind.imageIcon = petEggConf.icon
  self.bind.txtPetEggName = petEggConf.name
  local productGuid = L_ProductManager:getProductGuidBySpecialGuid(buildGuid, guid)
  local state = L_ProductManager:getProductState(buildGuid, productGuid)
  if state ~= L_HomeConst.ProductQueueState.NONE then
    self.bind.activeHatching = state == L_HomeConst.ProductQueueState.RUNNING
    self.bind.activeInQueue = state == L_HomeConst.ProductQueueState.WAITING
    self.bind.activeHatched = state == L_HomeConst.ProductQueueState.FINISH
    L_TimerManager:newOrResetTimer(self, "refresh", function()
      self:refreshView(self.guid, self.buildGuid)
    end, 1, -1)
  else
    self.bind.activeHatching = false
    self.bind.activeInQueue = false
    self.bind.activeHatched = false
    L_TimerManager:clearTimer(self)
  end
end

function cls:close()
  L_TimerManager:clearTimer(self)
end

return cls
