local this = {}
local PrePath_mapExploreLvUp = "Program/FlyMsg/pre_mapExploreLvUp.prefab"

function this:initMapExploreLvUp()
  self.mapExploreLvUpQueue = L_Struct.getQueue()
  self._mapExploreLevelParams = {}
end

function this:showMapExploreLvUp(popup)
  local priorityShowData = require("ui.manager.priorityShowQueue.flyMsgPriorityShowData").new({
    flyMsgType = L_ShowQueueConst.flyMsgType.exploreLvUp,
    uuid = self:getNextUniqueId(),
    params = {popup}
  })
  L_PriorityShowQueueManager:addPriorityShowData(priorityShowData)
end

function this:rawShowMapExploreLvUp(uuid, popup)
  popup._uuid = uuid
  self.mapExploreLvUpQueue:enQueue(popup)
  if self.mapExploreLvUpQueue:getLength() > 1 then
    return
  end
  self:doMapExploreLvUp()
end

function this:doMapExploreLvUp()
  local popup = self.mapExploreLvUpQueue:getFirst()
  if popup == nil then
    return
  end
  local _end = function(go)
    self._mapExploreLevelParams[go] = self._mapExploreLevelParams[go] or {}
    local goParam = self._mapExploreLevelParams[go]
    local trans = go.transform
    if goParam.rectTrans == nil then
      goParam.rectTrans = trans:GetComponent(typeof(C_RectTransform))
    end
    trans:Reset(self.normalRoot)
    trans.localScale = Unity.Vector3.one
    goParam.rectTrans.anchoredPosition = Unity.Vector2(-28, 224)
    if goParam.csGroup == nil then
      goParam.csGroup = trans:GetComponent(typeof(Unity.CanvasGroup))
    end
    goParam.csGroup.alpha = 1
    L_TimerManager:newOrResetTimer(go, "doNext", function()
      self.mapExploreLvUpQueue:deQueue()
      self.pool:despawn(go)
      self:doMapExploreLvUp()
      self:sendEvent(self.event.flyMsgPopupEnd, L_ShowQueueConst.flyMsgType.exploreLvUp, popup._uuid)
    end, 2.2)
  end
  self.pool:asyncSpawn(PrePath_mapExploreLvUp, _end)
end

function this:disposeMapExploreLvUp()
  for i, v in pairs(self._mapExploreLevelParams) do
    L_TimerManager:clearTimer(i)
    self.pool:despawn(i)
  end
  self._mapExploreLevelParams = {}
end

return this
