local this = {}
local _PreScienceExpTipPath = "Program/FlyMsg/pre_scienceExp.prefab"
local _ScienceExpTipModulePath = "ui.manager.flyMsg.moduleScienceExpTip"

function this:initHomeScienceExpTip()
  self.homeScienceExpTipCache = {}
end

function this:showHomeScienceExpTip(popup)
  if self.homeScienceExpTipCache[popup.technologyType] then
    return
  end
  self.homeScienceExpTipCache[popup.technologyType] = popup
  local priorityShowData = require("ui.manager.priorityShowQueue.flyMsgPriorityShowData").new({
    flyMsgType = L_ShowQueueConst.flyMsgType.homeScienceExp,
    uuid = self:getNextUniqueId(),
    params = {popup}
  })
  L_PriorityShowQueueManager:addPriorityShowData(priorityShowData)
end

function this:rawShowHomeScienceExpTip(uuid, popup)
  popup._uuid = uuid
  self:doHomeScienceExpTip(popup)
end

function this:doHomeScienceExpTip(popup)
  if popup == nil then
    return
  end
  if not self.homeScienceTipModule then
    self.homeScienceTipModule = require(_ScienceExpTipModulePath).new(G_UIModuleBase.ModuleType.Dynamic)
    self.homeScienceTipModule:created()
    local _end = function(go)
      self.homeScienceTip = go
      local trans = go.transform
      trans:Reset(self.leftRoot)
      trans.localScale = Unity.Vector3.one
      self.homeScienceTipModule:toBind(go:GetComponent(typeof(C_UIBinding)))
      self.homeScienceTipModule:setCloseCB(handler(self, self.onHomeScienceTipClose))
      self:doHomeScienceExpTip(popup)
    end
    self.pool:asyncSpawn(_PreScienceExpTipPath, _end)
  else
    self.homeScienceExpTipCache[popup.technologyType] = nil
    self.homeScienceTipModule:open(popup)
  end
end

function this:onHomeScienceTipClose(popup, level)
  self:sendEvent(self.event.flyMsgPopupEnd, L_ShowQueueConst.flyMsgType.homeScienceExp, popup._uuid)
end

function this:disposeHomeScienceExpTip()
  if self.homeScienceTipModule then
    self.homeScienceTipModule:unBind()
    self.homeScienceTipModule:disposeUIBinding()
    self.homeScienceTipModule = nil
  end
end

return this
