local this = {}
local PrePath_homeContentUnlock = "Program/FlyMsg/pre_homeContentUnlock.prefab"

function this:initHomeContentUnlock()
  self.homeContentUnlockQueue = L_Struct.getQueue()
  self._homeContentParams = {}
end

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

function this:rawShowHomeContentUnlock(uuid, popup)
  popup._uuid = uuid
  self.homeContentUnlockQueue:enQueue(popup)
  if self.homeContentUnlockQueue:getLength() > 1 then
    return
  end
  self:doHomeContentUnlock()
end

function this:doHomeContentUnlock()
  local popup = self.homeContentUnlockQueue:getFirst()
  if popup == nil then
    return
  end
  local _end = function(go)
    self._homeContentParams[go] = self._homeContentParams[go] or {}
    local goParam = self._homeContentParams[go]
    local trans = go.transform
    if goParam.rectTrans == nil then
      goParam.rectTrans = trans:GetComponent(typeof(C_RectTransform))
    end
    if goParam.customTween == nil then
      goParam.customTween = trans:GetComponent(typeof(C_LCustomTween))
    end
    goParam.customTween:DoKill_NoGCAlloc()
    trans:Reset(self.normalRoot)
    trans.localScale = Unity.Vector3.one
    goParam.rectTrans.anchoredPosition = Unity.Vector2(0, -67)
    if goParam.txt_name == nil then
      goParam.txt_name = L_GameUtil.findTranByName(go, "txt_name"):GetComponent(typeof(C_LTextMeshProUGUI))
      goParam.txt_name_white = L_GameUtil.findTranByName(go, "txt_name_white"):GetComponent(typeof(C_LTextMeshProUGUI))
    end
    if goParam.img_icon == nil then
      goParam.img_icon = L_GameUtil.findTranByName(go, "img_icon"):GetComponent(typeof(C_LImage))
    end
    local resInfo = L_HomeConst.HomeLevelUnlockModuleRes[popup.type]
    if resInfo then
      goParam.img_icon:LoadSprite(resInfo.icon)
      goParam.txt_name.text = L_WordsTpl:getValue(resInfo.unlockTip)
      goParam.txt_name_white.text = goParam.txt_name.text
    end
    if goParam.ani == nil then
      goParam.ani = trans:GetComponent(typeof(Unity.Animation))
    end
    L_TimerManager:newOrResetTimer(go, "doNext", function()
      goParam.ani:Stop()
      goParam.ani:Play("anim_home_tips_hide")
      L_TimerManager:newOrResetTimer(go, "doHide", function()
        self.homeContentUnlockQueue:deQueue()
        self.pool:despawn(go)
        self:doHomeContentUnlock()
        self:sendEvent(self.event.flyMsgPopupEnd, L_ShowQueueConst.flyMsgType.homeContentUnlock, popup._uuid)
      end, 0.167)
    end, 2)
  end
  self.pool:asyncSpawn(PrePath_homeContentUnlock, _end)
end

function this:disposeHomeContentUnlock()
  for i, v in pairs(self._homeContentParams) do
    if L_CommonUtil.isValid(v.customTween) then
      v.customTween:DoKill_NoGCAlloc()
    end
    L_TimerManager:clearTimer(i)
    self.pool:despawn(i)
  end
  self._homeContentParams = {}
end

return this
