#pragma once

#include <string>
#include <unordered_map>
#include <vector>

namespace tw::dbg {

class DebugWindow;

/**
 * The debug panels that exist right now.
 *
 * Panels are listed by whatever owns them, for as long as it lives, so the menu
 * follows what the client is currently doing. Whether a panel was open is kept
 * here rather than on the panel, since the owner is built again on every
 * reconnect and the panel would come back closed.
 */
class DebugWindowRegistry {
    std::vector<DebugWindow*> m_windows;

    /**
     * Keyed by panel id, remembered across the panels themselves.
     */
    std::unordered_map<std::string, bool> m_open_state;

public:
    /**
     * Lists a panel, restoring whether it was open last time one with the same
     * id was listed. Ownership stays with the caller, which has to remove it
     * again before the panel dies.
     */
    void add(DebugWindow* window);

    void remove(DebugWindow* window);

    /**
     * One submenu per category, listing every panel in it. Expects to be called
     * inside a menu bar.
     */
    void draw_menu();

    void draw_windows();
};

}
