#pragma once

#include <string>

namespace tw::dbg {

/**
 * A debug panel that can be toggled from the menu bar.
 *
 * The frame around a panel is drawn here so every one of them gets the same
 * close button and docking behaviour; subclasses only fill in the contents.
 */
class DebugWindow {
    std::string m_id;
    std::string m_title;
    std::string m_category;

    /**
     * The label handed to the ui, "title##id". Saved positions are keyed by the
     * whole label, so the visible half can change without losing the layout.
     */
    std::string m_label;

    bool m_open = false;

protected:
    /**
     * Fills the panel. Called only while it is open, between begin and end.
     */
    virtual void draw_contents() = 0;

public:
    DebugWindow(std::string id, std::string title, std::string category);
    virtual ~DebugWindow() = default;

    DebugWindow(const DebugWindow&) = delete;
    DebugWindow& operator=(const DebugWindow&) = delete;

    const std::string& id() const { return m_id; }
    const std::string& title() const { return m_title; }
    const std::string& category() const { return m_category; }

    bool is_open() const { return m_open; }
    void set_open(bool open) { m_open = open; }

    /**
     * The flag the menu item toggles, and the one the close button clears.
     */
    bool* open_flag() { return &m_open; }

    void draw();
};

}
