#include "DeerStudio/DeerStudio.h"
#include "DeerStudio/EditorEngine.h"
#include "DeerStudio/EditorEngine/DockPanel/DockPanelObject.h"
#include "DeerStudio/EditorEngine/DockPanel/DockPanelContext.h"

#include "imgui.h"

namespace Deer {
    namespace DeerStudio {
        void panelEnable(EditorEngine::DockPanelObject& dpo);
        
		void onPannelMenuBar() {
            if (ImGui::BeginMenu("Dock Panels Show/Hide")) {
                for (EditorEngine::DockPanelContext& pc : EditorEngine::dockPanelModules) {
                    if (pc.dockPanels.size() == 0)
                        continue;
                    
                    if (pc.dockPanels.size() == 1){
                        panelEnable(pc.dockPanels[0]);
                        continue;
                    }
                    
                    const char* name = pc.getName();
                    if (ImGui::BeginMenu(name)) {
                        for (EditorEngine::DockPanelObject& panel : pc.dockPanels) {
                            panelEnable(panel);
                        }
                        ImGui::EndMenu();
                    }
                }
                ImGui::EndMenu();
            }
        }

        void panelEnable(EditorEngine::DockPanelObject& dpo) {
            const char* name = dpo.getName();
            
            bool enabled = dpo.getFlag(DockPannelFlag_ShowPannel);
            if (ImGui::MenuItem(name, nullptr, enabled)) {
                dpo.setFlag(DockPannelFlag_ShowPannel, !enabled);
            }
        }
    }
}