#if TOOLS
using Godot;

namespace Mr.BrickAdventures.Tools.CaLevelGenerator;

[Tool]
public partial class CaLevelGeneratorPlugin : EditorPlugin
{
    private CaLevelGeneratorDock _dock;

    public override void _EnterTree()
    {
        _dock = new CaLevelGeneratorDock { Plugin = this };
        AddControlToDock(DockSlot.RightUl, _dock);
        SceneChanged += OnSceneChanged;
    }

    public override void _ExitTree()
    {
        SceneChanged -= OnSceneChanged;
        RemoveControlFromDocks(_dock);
        _dock.QueueFree();
        _dock = null;
    }

    private void OnSceneChanged(Node sceneRoot)
    {
        _dock?.OnSceneChanged(sceneRoot);
    }

    public EditorUndoRedoManager UndoRedo => GetUndoRedo();
}
#endif
