local ListBox   = require "core.modules.menusystem.listbox"
local RadianceListMenu = require "game.modules.menus.list"
local PauseMenu = RadianceListMenu.ListMenu:extend()

local Widget = require "core.modules.menusystem.widgets"

local ResumeWidget    = RadianceListMenu.DualTextWidget:extend()
local RestartWidget   = RadianceListMenu.DualTextWidget:extend()
local ExitWidget      = RadianceListMenu.DualTextWidget:extend()

local gui         = require "game.modules.gui"

local WIDTH = 80
local HEIGHT = 72

function PauseMenu:new(subgame)
  local x, y
  x = 424/2 -  WIDTH/2
  y = 240/2 - (3*17)/2

  PauseMenu.super.new(self, subgame, "pauseMenu", x, y, WIDTH, 3, true)

  self:setSound(self.scene.assets.sfx["navigate"])
  self.isActive   = false
  self.isVisible  = false

  ResumeWidget(subgame)
  self:setCancelWidget()
  RestartWidget(subgame)
  ExitWidget(subgame)
end

--- MENU WIDGETS

function ResumeWidget:new(scene)
  ResumeWidget.super.new(self, scene, "pauseMenu", "Resume", "")
end

function ResumeWidget:action()
  self.menu.isActive = false
  self.menu.isVisible = false
  self.scene.world.isActive = true
  self.scene.assets.isActive = true
  self.scene:flushKeys()
end

function RestartWidget:new(scene)
  ResumeWidget.super.new(self, scene, "pauseMenu", "Restart", "")
end

function RestartWidget:action()
  self.scene:restartLevel()
  self.menu.isActive = false
  self.menu.isVisible = false
  self.scene.world.isActive = true
  self.scene.assets.isActive = true
  self.scene:flushKeys()
end

function ExitWidget:new(scene)
  ExitWidget.super.new(self, scene, "pauseMenu", "Exit", "")
end

function ExitWidget:action()
  self.scene:exitLevel()
end


return PauseMenu
