------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------

local love        = require 'love'
local assets      = require 'src.utils.asstmngr'
local make_class  = require 'src.utils.classes'
local GameState   = require 'src.gstates.gstate'
local Sprite      = require 'src.graphics.sprite'
local VBox        = require 'src.ui.vbox'


------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------

local BaseMenu = make_class(GameState)


------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------

function BaseMenu:_init(parent, name, index, bckg)
    GameState._init(self, name, index)

    self.parent = parent

    -- Create background sprite and container.
    self.background = Sprite(bckg)
    self.container  = VBox(15, 5, love.graphics.getWidth())

    -- Register the background and container into the asset manager.
    assets:register(self.name, self.background)
    assets:register(self.name, self.container)
end


function BaseMenu:mousemoved(x, y, dx, dy)
    self.container:mousemoved(x, y, dx, dy)
end


function BaseMenu:mousepressed(x, y, btn)
    self.container:mousepressed(x, y, btn)
end


function BaseMenu:mousereleased(x, y, btn)
    self.container:mousereleased(x, y, btn)
end


function BaseMenu:update()
    if not assets:done(self.name) then
        assets:update(self.name)
    end
end


function BaseMenu:draw()
    if assets:done(self.name) then
        self.background:draw()
        self.container:draw()
    else
        assets:draw()
    end
end


------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------

return BaseMenu
