local helper = asset.require("util/slide_deck_helper")
local deck = nil


asset.onInitialize(function()
  deck = helper.createDeck("example", {
    UseRadiusAzimuthElevation = true,
    RadiusAzimuthElevation = { 1.0, 0.0, 0.0 }, -- use for dome
    UsePerspectiveProjection = true,
    FaceCamera = true,
    Scale = 0.7
  })

  helper.addSlide(deck, "${DATA}/test2.jpg")
  helper.addSlide(deck, "${DATA}/test3.jpg")

  local interpolationDuration = 0.5

  -- Add global functions for controlling slide deck and bind to keys
  rawset(_G, "nextSlide", function()
    helper.goToNextSlide(deck, interpolationDuration)
  end)

  rawset(_G, "previousSlide", function()
    helper.goToPreviousSlide(deck, interpolationDuration)
  end)

  rawset(_G, "toggleSlides", function()
    helper.toggleSlides(deck, interpolationDuration)
  end)

  helper.setCurrentSlide(deck, 1)

  openspace.action.registerAction({
    Identifier = "slide_deck.prevslide",
    Name = "Previous slide",
    Command = "previousSlide()",
    Documentation = "Previous slide",
    GuiPath = "/Slides",
    IsLocal = false
  })
  openspace.bindKey("KP_4", "slide_deck.prevslide")

  openspace.action.registerAction({
    Identifier = "slide_deck.nextslide",
    Name = "Next slide",
    Command = "nextSlide()",
    Documentation = "Next slide",
    GuiPath = "/Slides",
    IsLocal = false
  })
  openspace.bindKey("KP_6", "slide_deck.nextslide")

  openspace.action.registerAction({
    Identifier = "slide_deck.toggleslides",
    Name = "Toggle slides",
    Command = "toggleSlides()",
    Documentation = "Toggle slides",
    GuiPath = "/Slides",
    IsLocal = false
  })
  openspace.bindKey("KP_0", "slide_deck.toggleslides")

end)


asset.onDeinitialize(function()
  openspace.clearKey("KP_6")
  openspace.clearKey("KP_4")
  openspace.clearKey("KP_0")
  helper.removeDeck(deck)
end)
