local BasicPage = Object:extend()

local menu = require "game.modules.menus.fancy"
local gui = require "game.modules.gui"
local const = require "scenes.overworld.screens.mainmenu.const"

local ComplexHPBar = require "game.modules.gui.complexhpbar"

local HPBAR_SIZE = 80

function BasicPage:new(view, character)
  self.view = view
  self.character = game.characters.list[character]

  self.statBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 48+8)
  self.nameBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 40)

  self.hpbar = ComplexHPBar(HPBAR_SIZE)
  self.ppbar = ComplexHPBar(HPBAR_SIZE)
  self.hpbar:setColorForeground(248/255, 160/255, 0, 1)
  self.hpbar:setColorBackground(112/255, 0, 0)
  self.ppbar:setColorForeground(0, 248/255, 248/255, 1)
  self.ppbar:setColorBackground(0, 54/255, 229/255)
end

function BasicPage:getMenuWidgets()

end

function BasicPage:update(dt)

end

function BasicPage:draw()
  self:drawIdentity(const.X, const.Y)
  self:drawHPPP(const.X, const.Y + 48)
  self:drawLevel(const.X, 100)
  self:drawStats(const.X, 160)
  --self:drawWeakStrong(const.X, 160)
end

function BasicPage:drawIdentity(x, y)
  local identityString = self.character.fullname .. "\n"
  identityString = identityString .. "Class: " .. self.character.data.class

  love.graphics.draw(self.nameBox, x, y)
  self.view.scene.assets.fonts["small"]:draw(identityString, x + 6, y + 4, -1, "left")
end

function BasicPage:drawHPPP(x, y)
  self.view.scene.assets.fonts["hudnbrs_small"]:set()
  self.hpbar:drawWithLabels(x, y - 4, self.character.hp, self.character.stats.hpmax)
  local xx = x + const.CHARPAGESIZE - HPBAR_SIZE - 7
  self.ppbar:drawWithLabels(xx, y - 4, self.character.pp, self.character.stats.ppmax)
end

function BasicPage:drawLevel(x, y)
  local levelString = "Level: " .. self.character.level .. "\n"
  local levelString = levelString .. "Current exp: " .. self.character.exp .. "\n"
  local levelString = levelString .. "Next level: " .. self.character.exp_next

  love.graphics.draw(self.statBox, x, y)
  self.view.scene.assets.fonts["small"]:draw(levelString, x + 6, y + 4, -1, "left")
end

function BasicPage:drawStats(x, y)
  local statString = "ATK " .. self.character.stats.attack .. "0" .. "\n"
  statString = statString .. "DEF " .. self.character.stats.defense .. "0" .. "\n"

  local statString2 = "POW " .. self.character.stats.power .. "0" .. "\n"
  statString2 = statString2 .. "MND " .. self.character.stats.mind .. "0" .. "\n"

  local statString3 = "SPD " .. self.character.stats.speed .. "0" .. "\n"
  statString3 = statString3 .. "TEK " .. self.character.stats.technic .. "0"

  local pos1 = const.CHARPAGESIZE * (1/3)
  local pos2 = const.CHARPAGESIZE * (2/3)

  love.graphics.draw(self.nameBox, x, y)

  self.view.scene.assets.fonts["small"]:draw(statString,  x + 6,        y + 4, -1, "left")
  self.view.scene.assets.fonts["small"]:draw(statString2, x + 6 + pos1, y + 4, -1, "left")
  self.view.scene.assets.fonts["small"]:draw(statString3, x + 6 + pos2, y + 4, -1, "left")
end

function BasicPage:drawWeakStrong(x, y)
  local weakString = "Weak to: Earth, Lightning"
  local strongString = "Resist To: Fire"

  love.graphics.draw(self.nameBox, x, y)
  self.view.scene.assets.fonts["small"]:draw(weakString .. "\n" .. strongString, x + 6, y + 4, -1, "left")
end

return BasicPage
