local Scene = require "core.modules.scenes"
local menu = require "scenes.debug.menu.menu"

local DebugMenu = Scene:extend()

function DebugMenu:new()
  DebugMenu.super.new(self)
  self.assets:batchImport("scenes.debug.commons.assets")
  menu.commons.DebugMenu(self, "BaseMenu")
  menu.SceneWidget(self, "BaseMenu", scenes.title, "Launch Game")
  self:buildBattleMenu()
  self:buildOverworldMenu()
  self:buildSaveMenu()
  self:buildOtherMenu()
  self:buildOptionsMenu()
  menu.ExitWidget(self, "BaseMenu")

  self.menusystem:activate()
  self.menusystem:switchMenu("BaseMenu")
end

function DebugMenu:buildOptionsMenu()
  self:addSubMenu("options", "BaseMenu", "Options")
  self:addSubMenu("backgrounds", "options", "Set Background")
  menu.ShowBackgroundWidget(self, "options")

  menu.commons.SubMenuWidget(self, "backgrounds", "options", "Back")
  menu.commons.SubMenuWidget(self, "options", "BaseMenu", "Back")
end

function DebugMenu:buildOverworldMenu()
  self:addSubMenu("overworld", "BaseMenu", "Overworld")
  menu.commons.SubMenuWidget(self, "overworld", "BaseMenu", "Back")
end

function DebugMenu:buildBattleMenu()
  self:addSubMenu("combat", "BaseMenu", "Battle System")
  menu.SceneWidget(self, "combat", scenes.cbs, "Launch Battle")

  menu.commons.SubMenuWidget(self, "combat", "BaseMenu", "Back")
end

function DebugMenu:buildSaveMenu()
  self:addSubMenu("save", "BaseMenu", "Save System")
  menu.commons.SubMenuWidget(self, "save", "BaseMenu", "Back")
end

function DebugMenu:buildOtherMenu()
  self:addSubMenu("other", "BaseMenu", "Other gameplay")
  menu.SceneWidget(self, "other", scenes.test, "Minigame Engine")

  menu.commons.SubMenuWidget(self, "other", "BaseMenu", "Back")
end


function DebugMenu:update(dt)
  if (love.keyboard.isDown("space") and (not self.menusystem.isActive)) then
    self.menusystem:activate()
  end
end

function DebugMenu:addSubMenu(submenu, parent, name)
  local parent = parent or "BaseMenu"
   menu.commons.DebugMenu(self, submenu)
   menu.commons.SubMenuWidget(self, parent, submenu, name .. " >")
end

function DebugMenu:draw()
  if (self.menusystem.isActive) then
    self.assets.fonts["small"]:print("## SONIC RADIANCE - DEBUG MENU ##", 424/2, 8, "center")
    self.assets.fonts["small"]:print("v" .. game.version, 424 - 8, 240 - 22, "right")
  end
end

return DebugMenu;
