local toggle_sun = {
  Identifier = "os.toggle_sun",
  Name = "Toggle Sun",
  Command = [[
    if not is_declared("args") then
      openspace.printError("Cannot execute 'os.toggle_sun' manually")
      return
    end

    if not openspace.getPropertyValue("Scene.Sun.Renderable.Enabled") then
      openspace.setPropertyValueSingle("Scene.Sun.Renderable.Enabled", true)
    end

    if args.Transition == "Approaching" then
      openspace.setPropertyValueSingle("Scene.SunGlare.Renderable.Fade", 0.0, 1.0)
      openspace.setPropertyValueSingle("Scene.Sun.Renderable.Fade", 1.0, 1.0)
    else -- "Exiting"
      openspace.setPropertyValueSingle("Scene.SunGlare.Renderable.Fade", 1.0, 1.0)
      openspace.setPropertyValueSingle("Scene.Sun.Renderable.Fade", 0.0, 1.0)
    end
  ]],
  Documentation = [[Toggles the visibility of the Sun glare and the Sun globe when the 
    camera is approaching either so that from far away the Sun Glare is rendered and when
    close up, the globe is rendered instead]],
  GuiPath = "/Solar System/Sun",
  IsLocal = false
}

asset.onInitialize(function()
  openspace.action.registerAction(toggle_sun)
  openspace.event.registerEventAction(
    "CameraFocusTransition",
    toggle_sun.Identifier,
    { Node = "Sun", Transition = "Approaching" }
  )
  openspace.event.registerEventAction(
    "CameraFocusTransition",
    toggle_sun.Identifier,
    { Node = "Sun", Transition = "Exiting" }
  )
end)

asset.onDeinitialize(function()
  openspace.event.unregisterEventAction(
    "CameraFocusTransition",
    toggle_sun.Identifier,
    { Node = "Sun", Transition = "Exiting" }
  )
  openspace.event.unregisterEventAction(
    "CameraFocusTransition",
    toggle_sun.Identifier,
    { Node = "Sun", Transition = "Approaching" }
  )
  openspace.action.removeAction(toggle_sun)
end)


asset.meta = {
  Name = "Actions - Toggle current Trails",
  Version = "1.0",
  Description = "Asset providing actions to toggle trails",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
