local this = class("cameraController_menu", require("ui.manager.camera.controller.cameraController"))
local PATH_CAMERA = "Program/Camera/pre_menuCamera.prefab"

function this:ctor(mode)
  this.super.ctor(self, mode)
  local goVirCam = L_GameUtil.loadVirtualCamera(nil, PATH_CAMERA)
  self.virCamera = goVirCam:GetComponent(typeof(C_CinemachineVirtualCamera))
  self.cameraTactics = C_CameraManager.CreateMenuTactics(goVirCam, C_CinemachineBlendType.Cut, false)
end

function this:switchIn(preMode, params)
  if self.virCamera then
    local goVir = self.virCamera.gameObject
    goVir:ActiveTrans(true)
  end
  local mainContorl = L_PlayerManager:getMainControlEntity()
  self:bindEntity(mainContorl)
  self.cameraTactics:SetEnabled(true)
end

function this:switchOut(nextMode)
  if self.virCamera then
    self.virCamera.gameObject:ActiveTrans(false)
  end
end

function this:bindEntity(entity)
  self.cameraTactics.cineMachineCamera.Follow = entity:getTransform()
  self.cameraTactics.cineMachineCamera.LookAt = entity:getTransform()
  self:refreshVirCameraOffset(entity)
end

function this:onDestroy()
  this.super.onDestroy(self)
end

function this:refreshVirCameraOffset(entity)
  local body = self.virCamera:GetCinemachineComponent(0)
  local trackOffset = body.m_TrackedObjectOffset
  trackOffset.y = L_GameUtil.getCameraEntityOffsetY(entity)
  body.m_TrackedObjectOffset = trackOffset
  local rotation = L_Vector3.getRot(entity:getTransform())
  self.cameraTactics:SetCameraPOVHorizontal(rotation.y - 16.98)
  self.cameraTactics:SetCameraPOVVertical(0)
  self.cameraTactics:SetCameraFov(60)
  self.cameraTactics:SetCameraDis(1)
end

return this
