/*
 * Copyright 2023 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#include <imgui.h>

#include "objectexplorer-imgui.hpp"

namespace studio {

ObjectExplorerModel::ObjectExplorerModel(ox::StringParam name, ObjectExplorerModel *parent) noexcept:
		m_parent(parent),
		m_name(std::move(name)),
		m_fullPath(m_parent ? (m_parent->m_fullPath + "/" + m_name) : ox::String{}) {
}

void ObjectExplorerModel::draw(turbine::Context &ctx) const noexcept {
	constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
	if (!m_children.empty()) {
		if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
			for (auto const &child : m_children) {
				child->draw(ctx);
			}
			ImGui::TreePop();
		}
	} else {
		auto const name = ox::sfmt<ox::BasicString<255>>("{}##{}", m_name, m_fullPath);
		if (ImGui::TreeNodeEx(name.c_str(), ImGuiTreeNodeFlags_Leaf)) {
			if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
			}
			ImGui::TreePop();
		}
	}
}

}
