local ArrowManager = BaseClass("ArrowManager")
local ResourceManager = CS.GameEntry.Resource
local ParamData = {
  arrowType,
  positionType,
  position,
  pointId,
  uuid
}
local __init = function(self)
  self.param = nil
  self.fingerParam = nil
end
local __delete = function(self)
  self.param = nil
  self.fingerParam = nil
end
local ShowArrow = function(self, param)
  if self.fingerArrowObj then
    self.fingerArrowObj:Destroy()
    self.fingerArrowObj = nil
  end
  if param.position ~= nil then
    self.param = param
    if UIManager:GetInstance():IsWindowOpen(UIWindowNames.UIArrow) then
      EventManager:GetInstance():Broadcast(EventId.RefreshArrow)
    else
      UIManager:GetInstance():OpenWindow(UIWindowNames.UIArrow, {anim = true, playEffect = false})
    end
    EventManager:GetInstance():Broadcast(EventId.ArrowShow)
  end
end
local RemoveArrow = function(self)
  self.param = nil
  if UIManager:GetInstance():IsWindowOpen(UIWindowNames.UIArrow) then
    UIManager:GetInstance():DestroyWindow(UIWindowNames.UIArrow)
  end
end
local GetArrowParam = function(self)
  return self.param
end
local ShowFingerArrow = function(self, param)
  if self.fingerArrowObj then
    self.fingerArrowObj:Destroy()
    self.fingerArrowObj = nil
  end
  self.fingerParam = param
  if UIManager:GetInstance():IsWindowOpen(UIWindowNames.UIArrow) then
    EventManager:GetInstance():Broadcast(EventId.RefreshArrow)
  else
    UIManager:GetInstance():OpenWindow(UIWindowNames.UIFingerArrow, {anim = true, playEffect = false})
  end
end
local ShowWorldFingerArrow = function(self, pos)
  if UIManager:GetInstance():IsWindowOpen(UIWindowNames.UIArrow) then
    UIManager:GetInstance():DestroyWindow(UIWindowNames.UIArrow)
  end
  if UIManager:GetInstance():IsWindowOpen(UIWindowNames.UIFingerArrow) then
    if param and param.id == param.guidId then
      return
    end
    UIManager:GetInstance():DestroyWindow(UIWindowNames.UIFingerArrow)
    self.fingerParam = nil
  end
  if not self.fingerArrowObj then
    self.fingerArrowObj = ResourceManager:InstantiateAsync(UIAssets.WorldFingerArrow)
    self.fingerArrowObj:completed("+", function()
      if self.fingerArrowObj.isError then
        return
      end
      self.fingerArrowObj.gameObject:SetActive(true)
      self.fingerArrowObj.gameObject.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
      self.fingerArrowObj.gameObject.transform.position = pos
    end)
  else
    self.fingerArrowObj.gameObject.transform.position = pos
  end
end
local RemoveWorldFingerArrow = function(self)
  if self.fingerArrowObj then
    self.fingerArrowObj:Destroy()
    self.fingerArrowObj = nil
  end
end
local RemoveFingerArrow = function(self, isQuest)
  local param = self.fingerParam
  if isQuest then
    param = nil
  end
  if UIManager:GetInstance():IsWindowOpen(UIWindowNames.UIFingerArrow) then
    if param and param.id ~= nil and param.id == param.guidId then
      return
    end
    UIManager:GetInstance():DestroyWindow(UIWindowNames.UIFingerArrow)
    self.fingerParam = nil
  end
end
local GetFingerArrowParam = function(self)
  return self.fingerParam
end
local CloseAllArrow = function(self)
  self:RemoveArrow()
  self:RemoveFingerArrow()
  self:RemoveWorldFingerArrow()
end
ArrowManager.__init = __init
ArrowManager.__delete = __delete
ArrowManager.ShowArrow = ShowArrow
ArrowManager.RemoveArrow = RemoveArrow
ArrowManager.GetArrowParam = GetArrowParam
ArrowManager.ShowFingerArrow = ShowFingerArrow
ArrowManager.RemoveFingerArrow = RemoveFingerArrow
ArrowManager.GetFingerArrowParam = GetFingerArrowParam
ArrowManager.ShowWorldFingerArrow = ShowWorldFingerArrow
ArrowManager.RemoveWorldFingerArrow = RemoveWorldFingerArrow
ArrowManager.CloseAllArrow = CloseAllArrow
return ArrowManager
