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

////////////////////////////////////////////////////////////////////////////////////
//	Acknowledgements

#include "Acknowledgements.h"
#include "imgui.h"

namespace ApplicationFramework {

Acknowledgements::Acknowledgements()
{
}

Acknowledgements::~Acknowledgements()
{
}

// static
Acknowledgements& Acknowledgements::Get()
{
    static Acknowledgements singletonInstance;
    return singletonInstance;
}

void Acknowledgements::AddEntry(const AcknowledgementEntry& entry)
{
    m_acknowledgements.emplace_back(entry);
}

void Acknowledgements::Show(bool* p_open)
{
    if (ImGui::Begin("Acknowledgements", p_open))
    {
        ImGui::Text("Acknowledgements:");
        ImGui::Separator();
        for (auto& ack : m_acknowledgements)
        {
            if (ImGui::TreeNode(ack.name))
            {
                ImGui::Columns(2, "word-wrapping");
                ImGui::Text("Authors");
                ImGui::NextColumn();
                ImGui::Text("%s", ack.authors);
                ImGui::NextColumn();
                ImGui::Text("Copyright");
                ImGui::NextColumn();
                ImGui::Text("%s", ack.copyright);
                ImGui::NextColumn();
                ImGui::Text("License");
                ImGui::NextColumn();
                ImGui::Text("%s", ack.licenseType);
                ImGui::Columns(1);
                if (ImGui::TreeNode("License details"))
                {
                    ImGui::TextUnformatted((const char*)ack.licenseText.data, (const char*)(ack.licenseText.data + ack.licenseText.size));
                    ImGui::TreePop();
                }
                ImGui::TreePop();
            }
        }
        ImGui::End();
    }
}

} // ApplicationFramework namespace
