asset.require("./callisto/callisto")
asset.require("./europa/europa")
asset.require("./ganymede/ganymede")
asset.require("./io/io")



local JupiterMajorMoonsOn = {
  Identifier = "os.solarsystem.JupiterMajorMoonsOn",
  Name = "Turn ON major moons and trails",
  Command = [[
    local trails = openspace.getProperty("{moonTrail_major_jupiter}.Renderable.Enabled")
    local trails_fade = openspace.getProperty("{moonTrail_major_jupiter}.Renderable.Fade")

    local moons = openspace.getProperty("{moon_major_jupiter}.Renderable.Enabled")
    local moons_fade = openspace.getProperty("{moon_major_jupiter}.Renderable.Fade")

    for i, v in pairs(trails_fade) do
      openspace.setPropertyValueSingle(trails[i], true)
      openspace.setPropertyValueSingle(v, 1, 2, "Linear")
    end

    for i, v in pairs(moons_fade) do
      openspace.setPropertyValueSingle(moons[i], true)
      openspace.setPropertyValueSingle(v, 1, 2, "Linear")
    end
  ]],
  Documentation = "Turn ON Jupiter's major moons and their trails",
  GuiPath = "/Solar System/Jupiter",
  IsLocal = true
}

local JupiterMajorMoonsOff = {
  Identifier = "os.solarsystem.JupiterMajorMoonsOff",
  Name = "Turn OFF majors moon and trails",
  Command = [[
    local trails = openspace.getProperty("{moonTrail_major_jupiter}.Renderable.Enabled")
    local trails_fade = openspace.getProperty("{moonTrail_major_jupiter}.Renderable.Fade")

    local moons = openspace.getProperty("{moon_major_jupiter}.Renderable.Enabled")
    local moons_fade = openspace.getProperty("{moon_major_jupiter}.Renderable.Fade")

    for i, v in pairs(trails_fade) do
      openspace.setPropertyValueSingle(
        v,
        0,
        2,
        "Linear",
        "openspace.setPropertyValueSingle('" .. trails[i] .. "', false)"
      )
    end

    for i, v in pairs(moons_fade) do
      openspace.setPropertyValueSingle(
        v,
        0,
        2,
        "Linear",
        "openspace.setPropertyValueSingle('" .. moons[i] .. "', false)"
      )
    end
  ]],
  Documentation = "Turn OFF Jupiter's major moons and their trails",
  GuiPath = "/Solar System/Jupiter",
  IsLocal = true
}


asset.onInitialize(function()
  openspace.action.registerAction(JupiterMajorMoonsOn)
  openspace.action.registerAction(JupiterMajorMoonsOff)
end)

asset.onDeinitialize(function()
  openspace.action.removeAction(JupiterMajorMoonsOff)
  openspace.action.removeAction(JupiterMajorMoonsOn)
end)

asset.export("JupiterMajorMoonsOn", JupiterMajorMoonsOn.Identifier)
asset.export("JupiterMajorMoonsOff", JupiterMajorMoonsOff.Identifier)



asset.meta = {
  Name = "Jupiter Major Moons",
  Version = "1.1",
  Description = [[Meta asset containing Jupiters major moons: Callisto, Europa,
    Ganymede, and Io]],
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
