#pragma once

#include "Window.h"
#include "SharedMemory.h"
#include "AbstractUiInterface.h"

#include "wayland-client.h"
#include "xdg-shell-client-protocol.h"

#include <vector>
#include <memory>

class WaylandBuffer;
class WaylandSeatInterface;
class WaylandEglInterface;

class WaylandInterface : public AbstractUIInterface
{

public:
    WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true);

    ~WaylandInterface();

    void loop() override;

    void addWindow(mt::Window* window) override;

    void showWindow(mt::Window* window) override;

private:
    void initialize() override;

    void initializeHardwareRendering() override;

    void shutDown() override;

    static void registryHandleGlobalEvent(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);
    static void registryHandleGlobalRemoveEvent(void *data, struct wl_registry *registry, uint32_t name);

    void doXdgPong(uint32_t serial);

    void setCompositor(wl_compositor* compositor);

    void setSharedMemory(wl_shm* shared_memory);

    void setSeat(wl_seat* seat);

    void setXdgBase(xdg_wm_base* xdg_base);

    wl_display* mDisplay{nullptr};
    wl_compositor* mCompositor{nullptr};
    wl_registry_listener mRegistryListener;

    xdg_wm_base* mXdgBase{nullptr};
    xdg_wm_base_listener mXdgBaseListener;

    std::shared_ptr<WaylandBuffer> mBuffer;
    std::unique_ptr<WaylandSeatInterface> mSeatInterface;
    std::unique_ptr<WaylandEglInterface> mEglInterface;
};
