/******************************************************************************
*	File		-	panel_manager.h
*	Author		-	Joey Pollack
*	Date		-	2022/02/07 (y/m/d)
*	Mod Date	-	2022/02/07 (y/m/d)
*	Description	-	Manage the editor panels
******************************************************************************/

#ifndef PANEL_MANAGER_H_
#define PANEL_MANAGER_H_

#include "panel_defs.h"
#include <utils/op_res.h>
#include <dearimgui/imgui.h>
#include <map>
#include <vector>

struct ImGuiWindowClass;

namespace lunarium{
    class IGraphics;
    class Panel;

    class PanelManager
    {

    public:
        PanelManager();
        OpRes Initialize(std::string name, bool split_bottom = false);
        void Shutdown();

        // Panel interface
        [[nodiscard]] OpRes AddPanel(Panel* panel, uint32_t& id);
        void OpenPanel(uint32_t id);
        void ClosePanel(uint32_t id);
        bool IsOpen(uint32_t id);
        Panel* GetPanel(uint32_t id);
        const ImGuiWindowClass* GetWindowClass() const;

        // Docking
        bool IsBottomSplit() const;
        void SetSplitBottom(bool split_bottom);
        void ResetDocking();

        void OnTick(double delta);
        void MakeDockSpaces();
        void RenderPanels();

    private:
        std::string mName;
        bool mSplitBottom;  // If true the bottom dock node will also be split into left/right
        bool mResetDockSpace;
        std::vector<Panel*> mPanels;
        std::map<const char*, Panel*> mPanelsByName;
        unsigned int mDockSpaceID;
        ImGuiWindowClass mWindowClass;
        std::map<PanelDockZone, unsigned int> mDockZoneIDs;

    private:
        void DestoryPanels();


    };
}

#endif  // PANEL_MANAGER_H_