#pragma once

#include <pake/dirtiable-image.hpp>
#include <pake/widget.hpp>
#include <memory>

namespace pake {

  //a window / a connection to the compositor.
  class window {

    //the socket that connects us to the compositor
    euler::syscall::stream_handle socket;

    //the size of the window
    int width;
    int height;

    //the rendered contents of the window. pixels are dirty when
    //the compositor has not been informed of them changing.
    dirtiable_image contents;

    //the root widget, or an unset pointer if there is no root widget set
    std::unique_ptr<widget> root;

  public:
    //create a new window / connection to the compositor
    window(int width, int height, const std::string &title);

    //destroy the window / connection to the compositor
    ~window();

    //tell the compositor to show this window. you probably want to call
    //set_root and render_and_send_to_compositor before calling this.
    void show();

    //tell the compositor to hide this window
    void hide();

    //set the root widget. the widget is notified that its size is the
    //size of the window, and then it is rendered with force = true.
    void set_root(std::unique_ptr<widget> &&w);

    //get the root widget (assumes there is one)
    widget *get_root();

    //renders the root widget with force = false and
    //then sends the new contents to the compositor.
    void render_and_send_to_compositor();

  };

}
