/*
	Terminal
	by John Ryland
	Copyright (c) 2023
*/

////////////////////////////////////////////////////////////////////////////////////
//	Terminal Window

#include "imgui.h"
#include "TerminalWindow.h"
#include "TerminalView.h"
#include "IUiSystem.h"
#include "Window.h"
#include "Acknowledgements.h"
#include "Application.h"
#include "imgui.h"
#include <algorithm>

namespace GameEngine {

TerminalWindow::TerminalWindow(ApplicationFramework::IApplication& app, int width, int height, const char* title)
    : Window(app, width, height, title)
    , m_application(app)
    , m_terminalView(app)
{
}

// virtual
TerminalWindow::~TerminalWindow()
{
}

// virtual
void TerminalWindow::Initialize()
{
    ImGuiIO& io = ImGui::GetIO();
    // io.ConfigFlags = io.ConfigFlags & ~ImGuiConfigFlags_ViewportsEnable;         // Disable Multi-Viewport / Platform Windows
    Window::Initialize();
    m_terminalView.Initialize();
}

// virtual
void TerminalWindow::Shutdown()
{
    m_terminalView.Shutdown();
    Window::Shutdown();
}

// virtual
void TerminalWindow::Update()
{
    Window::Update();

    // Dockspace app
    ImGui::DockSpaceOverViewport();

    if (ImGui::BeginMainMenuBar())
    {
        if (ImGui::BeginMenu("File"))
        {
            if (ImGui::MenuItem("New")) {}
            ImGui::Separator();
            if (ImGui::MenuItem("Quit", "Alt+F4")) {}
            ImGui::EndMenu();
        }
        if (ImGui::BeginMenu("Edit"))
        {
            if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
            if (ImGui::MenuItem("Redo", "CTRL+Y", false, false)) {}  // Disabled item
            ImGui::Separator();
            if (ImGui::MenuItem("Cut", "CTRL+X")) {}
            if (ImGui::MenuItem("Copy", "CTRL+C")) {}
            if (ImGui::MenuItem("Paste", "CTRL+V")) {}
            ImGui::EndMenu();
        }
        if (ImGui::BeginMenu("View"))
        {
            m_terminalView.AddShowMenuItem();
            ImGui::EndMenu();
        }
        if (ImGui::BeginMenu("Help"))
        {
            ImGui::MenuItem("Acknowledgements", NULL, &m_show_acknowledgements);
            ImGui::MenuItem("About Terminal", NULL, &m_show_app_about);
            ImGui::EndMenu();
        }
        ImGui::EndMainMenuBar();
    }

    //if (m_show_app_about)
    //    ImGui::ShowAboutWindow(&m_show_app_about);
    if (m_show_acknowledgements)
        ApplicationFramework::Acknowledgements::Get().Show(&m_show_acknowledgements);

    ImGui::SetNextWindowViewport(ImGui::GetMainViewport()->ID);
    m_terminalView.Update();
}

} // GameEngine namespace
