local FadeUpTrails = {
  Identifier = "os.planetsmoons.FadeUpTrails",
  Name = "Show planet and moon trails",
  Command = [[
    openspace.setPropertyValue("{planetTrail_solarSystem}.Renderable.Fade", 1, 2)
    openspace.setPropertyValue("{moonTrail_solarSystem}.Renderable.Fade", 1, 2)
  ]],
  Documentation = "Fade up all planet and moon trails in the Scene",
  GuiPath = "/Trails",
  IsLocal = true
}

local FadeDownTrails = {
  Identifier = "os.planetsmoons.FadeDownTrails",
  Name = "Hide planet and moon trails",
  Command = [[
    openspace.setPropertyValue("{planetTrail_solarSystem}.Renderable.Fade", 0, 2)
    openspace.setPropertyValue("{moonTrail_solarSystem}.Renderable.Fade", 0, 2)
  ]],
  Documentation = "Fade down all planet and moon trails in the Scene",
  GuiPath = "/Trails",
  IsLocal = true
}

local ToggleTrails = {
  Identifier = "os.planetsmoons.ToggleTrails",
  Name = "Toggle planet and moon trails",
  Command = [[
    local capList = openspace.getProperty("{planetTrail_solarSystem}.Renderable.Fade")
    local list = openspace.getProperty("{moonTrail_solarSystem}.Renderable.Fade")
    if (#capList == 0) and (#list == 0) then
      openspace.printWarning("No trails to toggle")
    else
      local prop
      if (#capList > 0) then
        prop = capList[1]
      else
        prop = list[1]
      end
      local currentFade = openspace.getPropertyValue(prop)
      local newFade = 0
      if currentFade < 1 then
        newFade = 1
      end
      openspace.setPropertyValue("{planetTrail_solarSystem}.Renderable.Fade", newFade, 2)
      openspace.setPropertyValue("{moonTrail_solarSystem}.Renderable.Fade", newFade, 2)
    end
  ]],
  Documentation = "Toggle fade for planet and moon trails in the Scene",
  GuiPath = "/Trails",
  IsLocal = true
}


asset.onInitialize(function()
  openspace.action.registerAction(FadeUpTrails)
  openspace.action.registerAction(FadeDownTrails)
  openspace.action.registerAction(ToggleTrails)
end)

asset.onDeinitialize(function()
  openspace.action.removeAction(ToggleTrails)
  openspace.action.removeAction(FadeDownTrails)
  openspace.action.removeAction(FadeUpTrails)
end)

asset.export("FadeUpTrails", FadeUpTrails.Identifier)
asset.export("FadeDownTrails", FadeDownTrails.Identifier)
asset.export("ToggleTrails", ToggleTrails.Identifier)
