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

local make_class = require 'src.utils.classes'
local Drawable   = require 'src.graphics.drawable'


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

local DialogManager = make_class(Drawable)


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

function DialogManager:_init()
    Drawable._init(self)
    self.dialogs = {}
    self.count   = 0
end


function DialogManager:add(dialog)
    self.dialogs[dialog] = true
    self.count           = self.count + 1
end


function DialogManager:remove(dialog)
    self.dialogs[dialog] = nil
    self.count           = math.max(self.count - 1, 0)
end


function DialogManager:empty()
    return self.count == 0
end


function DialogManager:update(dt)
    for d, _ in pairs(self.dialogs) do
        d:update(dt)
    end
end


function DialogManager:draw()
    for d, _ in pairs(self.dialogs) do
        d:draw()
    end
end


function DialogManager:keypressed(key, code, isrepeat)
    for d, _ in pairs(self.dialogs) do
        d:keypressed(key, code, isrepeat)
    end
end


function DialogManager:textinput(text)
    for d, _ in pairs(self.dialogs) do
        d:textinput(text)
    end
end


function DialogManager:keyreleased(key, code)
    for d, _ in pairs(self.dialogs) do
        d:keyreleased(key, code)
    end
end


function DialogManager:mousemoved(x, y, dx, dy)
    for d, _ in pairs(self.dialogs) do
        d:mousemoved(x, y, dx, dy)
    end
end


function DialogManager:mousepressed(x, y, btn)
    for d, _ in pairs(self.dialogs) do
        d:mousepressed(x, y, btn)
    end
end


function DialogManager:mousereleased(x, y, btn)
    for d, _ in pairs(self.dialogs) do
        d:mousereleased(x, y, btn)
    end
end


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

return DialogManager()
