#pragma once

#include <vector>
#include <memory>

#include "Window.h"
#include "DrawingContext.h"

#include "PaintEvent.h"
#include "MouseEvent.h"
#include "ResizeEvent.h"
#include "KeyboardEvent.h"

class Widget;
class DesktopManager;

class WindowManager
{
public:
    WindowManager(DesktopManager* desktopManager);

    ~WindowManager();

    static std::unique_ptr<WindowManager> Create(DesktopManager* desktopManager);

    void addWindow(WindowUPtr window);

    mt::Window* getMainWindow() const;

    void onPaintEvent(const PaintEvent* event);

    void onMouseEvent(const MouseEvent* event);

    void onKeyboardEvent(const KeyboardEvent* event);

    void onResizeEvent(const ResizeEvent* event);

    void clearPlatformWindows();

    std::size_t getNumWindows() const
    {
        return mWindows.size();
    }

    mt::Window* getWindow(std::size_t idx) const
    {
        return mWindows[idx].get();
    }

    void onLoopIteration(mt::Screen* screen);

    void onAddPopupWindow(mt::Window* parent, std::unique_ptr<Widget> widget);

private:
    std::vector<WindowUPtr> mWindows;
    DrawingMode mDrawMode{ DrawingMode::GRAPH };
    DesktopManager* mDesktopManager{nullptr};
};

using WindowManagerUPtr = std::unique_ptr<WindowManager>;
