#ifndef EDITSCENE_INLINE_BEHAVIOR_TREE_EDITOR_HPP
#define EDITSCENE_INLINE_BEHAVIOR_TREE_EDITOR_HPP
#pragma once

#include "../components/BehaviorTree.hpp"
#include <imgui.h>

/**
 * Inline behavior tree editor that can edit any BehaviorTreeNode
 * without requiring a BehaviorTreeComponent wrapper.
 */
class InlineBehaviorTreeEditor {
public:
	static bool render(BehaviorTreeNode &root);

private:
	struct EditOp {
		enum Type { Add, Remove, Move, AddLuaNode } type;
		BehaviorTreeNode *parent = nullptr;
		size_t childIndex = 0;
		Ogre::String addType;
		Ogre::String luaNodeName;
		int moveDelta = 0;
	};

	static void queueOp(EditOp op);
	static void applyOps(BehaviorTreeNode &root);
	static void renderNode(BehaviorTreeNode &node, BehaviorTreeNode *parent,
			       BehaviorTreeNode *&selected, int &id);
	static void renderProps(BehaviorTreeNode *node);
	static bool renderLuaNodeSubmenu(BehaviorTreeNode *parent,
					 size_t childIndex);
	static std::vector<EditOp> &getOps();
};

#endif // EDITSCENE_INLINE_BEHAVIOR_TREE_EDITOR_HPP
