local commons = require "scenes.debug.commons.menu"
local listMenu = require "game.modules.menus.list"

local menu = {}
menu.commons = commons
menu.ExitWidget = listMenu.DualTextWidget:extend()
menu.SaveWidget = listMenu.DualTextWidget:extend()
menu.LoadWidget = listMenu.DualTextWidget:extend()
menu.LevelUpWidget = listMenu.DualTextWidget:extend()
menu.AddRemoveWidget = listMenu.DualTextWidget:extend()
menu.ChangeLeaderWidget = listMenu.DualTextWidget:extend()
menu.ItemWidget = listMenu.DualTextWidget:extend()

-- ExitWidget
function menu.ExitWidget:new(scene, menuName)
  menu.ExitWidget.super.new(self, scene, menuName, "Exit", "")
end

function menu.ExitWidget:action()
  love.event.quit("000")
end

-- Save game
function menu.SaveWidget:new(scene, menuName)
  menu.SaveWidget.super.new(self, scene, menuName, "Save game", "")
end

function menu.SaveWidget:action()
  game:write()
end

-- Save game
function menu.LoadWidget:new(scene, menuName, slot)
  menu.LoadWidget.super.new(self, scene, menuName, "Load file ", slot)
  self.slot = slot
end

function menu.LoadWidget:action()
  game:read(self.slot)
end

-- Level Up
function menu.LevelUpWidget:new(scene, menuName, character)
  menu.LevelUpWidget.super.new(self, scene, menuName, "Levelup to", character.level + 1)
  self.character = character
end

function menu.LevelUpWidget:action()
  self.character:levelUp()
end

-- Add Remove Widget
function menu.AddRemoveWidget:new(scene, menuName, character)
  menu.AddRemoveWidget.super.new(self, scene, menuName, "Add/Remove", character.name)
  self.character = character
end

function menu.AddRemoveWidget:action()
  game.characters:addOrRemoveToTeam(self.character.simplename)
end

--Change Team Leader
function menu.ChangeLeaderWidget:new(scene, menuName)
  menu.ChangeLeaderWidget.super.new(self, scene, menuName, "Change active character", "")
end

function menu.ChangeLeaderWidget:action()
  game.characters:setActiveCharacter(1)
end

-- ItemWidget
function menu.ItemWidget:new(scene, menuName, itemdata)
  menu.ItemWidget.super.new(self, scene, menuName, itemdata.fullname, "")
  self.category = menuName
  self.itemName = itemdata.name
end

function menu.ItemWidget:action()
  game.loot:addItem(self.category, self.itemName, 1)
end


return menu
