#pragma once

#include "IPlatformWindow.h"

class XcbImage;
class XcbScreen;
class XcbGlWindowInterface;
class XcbGlInterface;

class FontsManager;

struct xcb_connection_t;

namespace mt
{
    class Window;
}

class XcbWindow : public IPlatformWindow
{
public:
    XcbWindow(mt::Window* window, int hwnd, xcb_connection_t* connection, XcbGlInterface* xcbGlInterface);
    virtual ~XcbWindow();

    static void add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, FontsManager* fontsManager, XcbGlInterface* xcbGlInterface);

    int getHandle() const;
    unsigned getGraphicsContext() const;

    void show() override;

    void beforePaint(mt::Screen* screen) override;

    void afterPaint(mt::Screen* screen) override;

    void clear() override;

    void map() override;

    void onResize(unsigned width, unsigned height) override;

private:
    int mHandle{-1};
    unsigned mGraphicsContext {0};
    xcb_connection_t* mConnection{nullptr};
    std::unique_ptr<XcbImage> mBackingImage;
    std::unique_ptr<XcbGlWindowInterface> mGlInterface;
};

using XcbWindowPtr = std::unique_ptr<XcbWindow>;

