local LookUp = {
  Identifier = "os.nightsky.LookUp",
  Name = "Look up",
  Command = [[
    local currentNavState = openspace.navigation.getNavigationState()
    local newNavState = {
      Pitch = math.pi,
      Anchor = currentNavState["Anchor"],
      Yaw = currentNavState["Yaw"],
      Position = currentNavState["Position"],
      Up = currentNavState["Up"]
    }
    openspace.navigation.setNavigationState(newNavState)
  ]],
  Documentation = "Sets the view to be looking at the zenith",
  GuiPath = "/Night Sky/View",
  IsLocal = false
}

local LevelHorizonYaw = {
  Identifier = "os.nightsky.LevelHorizonYaw",
  Name = "Level Horizon Yaw",
  Command = [[
    local currentNavState = openspace.navigation.getNavigationState()
    local newNavState = {
      Pitch = currentNavState["Pitch"],
      Anchor = currentNavState["Anchor"],
      Yaw = 0.0,
      Position = currentNavState["Position"],
      Up = currentNavState["Up"]
    }
    openspace.navigation.setNavigationState(newNavState)
  ]],
  Documentation = "Levels the horizon horizontally.",
  GuiPath = "/Night Sky/View",
  IsLocal = false
}

local LevelHorizonPitch = {
  Identifier = "os.nightsky.LevelHorizonPitch",
  Name = "Level Horizon Pitch",
  Command = [[
    local currentNavState = openspace.navigation.getNavigationState()
    local newNavState = {
      Pitch = math.pi / 2.0,
      Anchor = currentNavState["Anchor"],
      Yaw = currentNavState["Yaw"],
      Position = currentNavState["Position"],
      Up = currentNavState["Up"]
    }
    openspace.navigation.setNavigationState(newNavState)
  ]],
  Documentation = "Levels the view to the horizon.",
  GuiPath = "/Night Sky/View",
  IsLocal = false
}

local LookingNorth = {
  Identifier = "os.nightsky.LookingNorth",
  Name = "Looking North",
  Command = [[
    local currentNavState = openspace.navigation.getNavigationState()
    local newNavState = {
      Pitch = math.pi / 2.0,
      Anchor = currentNavState["Anchor"],
      Yaw = currentNavState["Yaw"],
      Position = currentNavState["Position"],
      Up = { 0.0, 0.0, 1.0 }
    }
    openspace.navigation.setNavigationState(newNavState)
  ]],
  Documentation = "Sets the view for a horizon looking North.",
  GuiPath = "/Night Sky/View",
  IsLocal = false
}

local LookingSouth = {
  Identifier = "os.nightsky.LookingSouth",
  Name = "Looking South",
  Command = [[
    local currentNavState = openspace.navigation.getNavigationState()
    local newNavState = {
      Pitch = math.pi / 2.0,
      Anchor = currentNavState["Anchor"],
      Yaw = currentNavState["Yaw"],
      Position = currentNavState["Position"],
      Up = { 0.0, 0.0, -1.0 }
    }
    openspace.navigation.setNavigationState(newNavState)
  ]],
  Documentation = "Sets the view for a horizon looking South.",
  GuiPath = "/Night Sky/View",
  IsLocal = false
}


asset.onInitialize(function()
  openspace.action.registerAction(LookUp)
  openspace.action.registerAction(LevelHorizonYaw)
  openspace.action.registerAction(LevelHorizonPitch)
  openspace.action.registerAction(LookingNorth)
  openspace.action.registerAction(LookingSouth)
end)

asset.onDeinitialize(function()
  openspace.action.removeAction(LookingSouth)
  openspace.action.removeAction(LookingNorth)
  openspace.action.removeAction(LevelHorizonPitch)
  openspace.action.removeAction(LevelHorizonYaw)
  openspace.action.removeAction(LookUp)
end)

asset.export("LookUp", LookUp.Identifier)
asset.export("LevelHorizonYaw", LevelHorizonYaw.Identifier)
asset.export("LevelHorizonPitch", LevelHorizonPitch.Identifier)
asset.export("LookingNorth", LookingNorth.Identifier)
asset.export("LookingSouth", LookingSouth.Identifier)
